Can someone provide a code sample to add values to a combobox please? Do you use the AddItems property?
Thanks!
Can someone provide a code sample to add values to a combobox please? Do you use the AddItems property?
Thanks!
A combo box can be populated in a number of ways which will need different methods to add to it. Please show us the "Row Source Type" property setting and the "Row Source" property setting.
Can you tell us a bit more about the data in the combo box and what you want to do.
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
I posted my issue a day or 2 ago and got a reply with a possible solution but I am inexperienced and on a tight timeline so I was hoping for something a little quicker and less complicated. Here is the link to the thread: https://www.accessforums.net/showthr...340#post120340
I've decided to use only 2 comboboxes and have the second dependent on the selection from the first. Each field is in a separate table though.
I was hoping that I could use code to do something like what I have below where the combobox is cleared out each time the form is opened and populated with values based on what the user selects in the first combobox...
If cboOne = "A" Then
cboTwo options are [1,2,3]
Elseif cboOne ="B" Then
cboTwo options ae [10,20,30]
Elseif cboOne = "C" Then
cboTwo options are [100,200,300]
End if
The Row Source is blank/empty and the Row Source Type is set to "Value List" for cboTwo.
What you are looking for is "Cascading combo boxes". Try Googling that......
Maybe this is what you are trying to do:
Create a new form with two combo boxes called “ComBox1” and ComBox2”.Code:Private Sub ComBox1_AfterUpdate() 'Reset the value of ComBox2 Me.ComBox2 = "" Me.ComBox2.SetFocus End Sub Private Sub ComBox2_GotFocus() 'Find out the value of ComBox1 and then 'Set the list values of ComBox2 Select Case Me.ComBox1 Case Is = "fruit" Me.ComBox2.RowSourceType = "Value List" Me.ComBox2.RowSource = "Apple;Orange;Grape" Case Is = "Veg" Me.ComBox2.RowSourceType = "Value List" Me.ComBox2.RowSource = "Pea;Turnip;Grape" Case Else End Select End Sub Private Sub Form_Current() 'Empty and setup ComBox2 Me.ComBox2.RowSourceType = "Value List" Me.ComBox2.RowSource = "" 'Empty and setup ComBox1 Me.ComBox1.RowSourceType = "Value List" Me.ComBox1.RowSource = "Fruit;Veg" Me.ComBox1 = "" End Sub
Set the form’s On Current property to [Event Procedure]
Set the After Update event of ComBox1 to [Event Procedure]
Set the Got Focus event of ComBox2 to [Event Procedure]
See attached db
IMHO this is not the best way to handle this (that has already been given to you), but it should work.
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick