Mostly access user having problem to filter/fill combobox based on other combobox/control value. There is a simple way to do this.
Definition:
combobox/control: combobox/control: first control that has value (combox1)
combobox: second control as combobox that will fill by first control value (combox2)
Write code in to afterupdate event of combobox/control to set combobox rowsource.
Set combobox/control value to null
Set combobox rowsource properties with SQL statement, the SQL statement will have criteria in where clause to filter record from table.
And requery combobox to get up to date data.
If your form has more than one combobox that depends upon successive combobox, you can continue below process for each combobox except last combobox. And keep adding combobox value into your SQL where clause to filter unique records.
For Example,
Private Sub combox1_AfterUpdate()
combobox2= Null
combobox3= Null
combox2.RowSource = "SELECT DISTINCT Feild2 FROM Table1 " & _
" WHERE Field1='" & combox1 & "'"
combox2.Requery
End Sub
Private Sub combox2_AfterUpdate()
combobox3= Null
combox3.RowSource = "SELECT DISTINCT Feild3 FROM Table1 " & _
" WHERE Field1='" & combox1 & "' AND Field2='" & combox2 & "'"
combox3.Requery
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.