Populating list boxes during form initialisation

Populating list boxes during form initialisation

Anonymous
Not applicable
243 Views
2 Replies
Message 1 of 3

Populating list boxes during form initialisation

Anonymous
Not applicable
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
0 Likes
244 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
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
0 Likes
Message 3 of 3

Anonymous
Not applicable
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 irtfnm use john at goodfellowassoc dot com "Laurie Comerford" wrote in message news:424e3e6a_2@newsprd01... > 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 > >
0 Likes