Unanswered: AutoFill combo box based on value of previous field selected
Auto-Fill a ComboBox field on a form based on the value of a previous ComboBox field on the same form – both fields come from the same table;
I have two Tables; HoofDoc and Koper.
HoofDoc contains two fields called; StuurAan and Adres
Koper contains two fields called; Koper_Ontvanger and Bestemming
I created a form “Data Toevoer” to add records to Hoofdoc where StuurAan = Koper_Ontvanger and Adres = Bestemming. For the StuurAan field I created a ComboBox called cboStuurAan where I select Koper_Ontvanger from the Koper table. For the Adres field I created a a ComboBox called cboAdres.
When I select the Koper_Ontvanger in the cboStuurAan combobox I want to Autofill the cboAdres combobox with the correct Bestemming from Koper.
I created the following code in cboStuurAan;
Private Sub cboStuurAan_AfterUpdate()
'Create a new rowsource for the Adres Combo box after selection of Koper_Ontvanger
'Verify that User selected a Koper_Ontvanger
If Len(cboStuurAan) > 0 Then
'set the Adres Rowsource to find only Adres for selected Kopr_Ontvanger
.RowSource = _
"SELECT ID,Bestemming " & _
"FROM Koper WHERE Koper_Ontvanger = " & cboStuurAan
'Repopulate the Adres Combo Box
'Add Dazzle by displaying list for the user
The result I get is an empty cboAdres combo box to select the Bestemming from.
Can you please help me. I am struggling for a week now , just to get this working.
Ranman, thank you for your proposal which I implemented.
I do get a list of Company’s now in my cboCo. The problem now is cboCo returns all records and not only the one’s associated to the State I selected in cboStates?