locked
Create "in memory" listbox RRS feed

  • Question

  • All

    I created a function which fills in a given listbox on a given form.  This works as expected

    FillInListbox lstMyListbox, frmForm, rs

    public sub FillInListbox(lst as ListBox, frm as Form, rs as RecordSet)

    while not rs.bof and not rs.eof frm(lst.name).Additem rs!Data

    rs.movenext wend

    end sub

    I am now in a situation where I need to fill in a "virtual listbox" so there is no real form nor a real listbox. So I want to assign the values to a listbox I create in the code.  Is this possible?

    public sub FillInListbox(lst as ListBox, frm as Form, rs as RecordSet)
    if lst = nothing then
    …
    else
    while not rs.bof and not rs.eof
    frm(lst.name).Additem rs!Data
    rs.movenext
    wend
    end if
    end sub

    Monday, October 14, 2019 12:33 PM

Answers

  • A list box doesn't exist in a vacuum. You'd have to open a form in design view. You can then use the Application.CreateControl method to create a list box on the form. Next, save the form and, if desired, open it in form view.

    I would not recommend doing this in a 'production' database...


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by kvhoof Monday, October 14, 2019 12:53 PM
    Monday, October 14, 2019 12:39 PM

All replies

  • A list box doesn't exist in a vacuum. You'd have to open a form in design view. You can then use the Application.CreateControl method to create a list box on the form. Next, save the form and, if desired, open it in form view.

    I would not recommend doing this in a 'production' database...


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by kvhoof Monday, October 14, 2019 12:53 PM
    Monday, October 14, 2019 12:39 PM
  • I am now in a situation where I need to fill in a "virtual listbox" so there is no real form nor a real listbox. So I want to assign the values to a listbox I create in the code.  Is this possible?

    Hi kvhoof,

    What do you want to do with this "virtual listbox"?

    Imb.

    Monday, October 14, 2019 6:07 PM