|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cascading Multiple Combo Boxes and display filtered results in a subform
Hi all,
I have another question about my program regarding combo boxes and subforms. I have 4 combo boxes that presently feed off each other in a specific order, so after cbo1 is selected it populates cbo2 with only those records that have the selected cbo1 entry and it then also filters the datasheet subform, then cbo2 populates cbo3 with those records associated with cbo1 and cbo2 and again filters the subform, then the same for cbo4. It works fine and I am really happy with how I have got it working (see example below) but what I would like to achieve is to allow the user to select any combo box in any order and reselect them as required with the list being filtered each time and the other combo boxes being populated to reflect the changes. Here is what I have at present in the AfterUpdate event of the first combo box 'Populate the Second Combo Box strSQL = "SELECT DISTINCT table.Item2 FROM table " strSQL = strSQL & " WHERE table.item1 = '" & cboitem1 & "'" strSQL = strSQL & " ORDER BY table.Item2;" cboItem2.RowSource = strSQL 'Populate the subform with all data for the selection strSQLSF = "SELECT * FROM table " strSQLSF = strSQLSF & " WHERE table.item1 = '" & cboItem1 & "'" Me!SelectItemSubForm.LinkChildFields = "Item1" Me!SelectItemSubForm.LinkMasterFields = "Item1" Me.RecordSource = strSQLSF Me.Requery and here is the AfterUpdate event of the third combo box 'Populate the sample date combo box strSQL = " SELECT DISTINCT table.Item4 FROM table " strSQL = strSQL & " WHERE table.Item1 = '" & cboItem1 & "' And " strSQL = strSQL & " table.Item2 = '" & cboItem2 & "' And " strSQL = strSQL & " table.Item3 = '" & cboItem3 & "'" strSQL = strSQL & " ORDER BY table.Item4;" cboItem4.RowSource = strSQL 'Populate the subform strSQLSF = " SELECT * FROM table " strSQLSF = strSQLSF & " WHERE table.Item1 = '" & cboItem1 & "' And " strSQLSF = strSQLSF & " table.Item2 = '" & cboItem2 & "' And " strSQLSF = strSQLSF & " table.Item3 = '" & cboItem3 & "'" 'Reset the relationship links Me!SelectItemSubForm.LinkChildFields = "" Me!SelectItemSubForm.LinkMasterFields = "" Me!SelectItemSubForm.LinkChildFields = "Item1;Item2;Item3" Me!SelectItemSubForm.LinkMasterFields = "Item1;Item2;Item3" Me.RecordSource = strSQLSF Me.Requery What I was thinking was to have a generic function set up for each of the 4 events and pass in the information to the functions but I cant quite think how to do it... Any ideas/suggestions on how to achieve what I am after? Cheers. |
|
#2
|
|||
|
|||
|
Sorted.
I wrote code to cover all situations and used an IF to check which combos were selected. There was probably an OO method of doing it but im too long out of the game to be trying it |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Cascading Multiple Combo Boxes and display filtered results in a subform |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|