Populating list boxes during form initialisation

Discussion in 'AutoCAD' started by Laurie Comerford, Apr 2, 2005.

  1. Hi,

    I'm reading data from a data base and using the data to populate two list
    boxes using the form Initialisation event.

    My ambition is to populate one list box first, set it's list index to 0 and
    then read the value from there as a selection parameter for populating the
    second list box.

    However, as I step through the code I find that the first list box has no
    value during the form initialisation.

    It makes no difference if I move the code to the Form Activate event during
    the initial opening of the form.

    Is this the normal way forms are activated - ie that list boxes have no
    readable data till the form actually appears to the user?

    I have used a work around by sending the first value in the first box to a
    temporary variable, but that seems inelegant.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, Apr 2, 2005
    #1
  2. Laurie Comerford

    fantum Guest

    It's hard to say what the problem might be without a look at the code. Does this do something like what you want?

    Private Sub ListBox1_Click()
    Dim s As String

    s = ListBox1.List(ListBox1.ListIndex)

    With ListBox2
    .Clear
    .AddItem s & "_1"
    .AddItem s & "_2"
    .AddItem s & "_3"
    .AddItem s & "_4"
    End With

    End Sub

    Private Sub UserForm_Initialize()
    With ListBox1
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
    .ListIndex = 0
    End With

    End Sub
     
    fantum, Apr 2, 2005
    #2
  3. If you are loading the first listbox from a recordset in its row order, then
    you should have the value for the second listbox's (recordset's) criteria in
    the first row of the first recordset. I'm guessing, maybe misunderstanding.
     
    John Goodfellow, Apr 2, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.