Multiple combo boxes

D

Deb H

I have a main form and subform with 2 combo boxes. One combo box
(cboFindHH)should filter the main form (based on Families table) and the
other combo box (cboFindChild) should filter the subform (based on Children
table). There is a one to many relationship between the tables. I have
modified code using the tip from Allen Browne's previous posts, but I can't
seem to be able to go from one combo box to the other. For example, if I
filter a particular head of household in the main form, I would then like to
apply a new filter based on all the records in the subform (or do the
reverse). However, when I try this, it is only searching on one record. Here
is my code:
Private Sub cboFindHH_AfterUpdate()
Dim strSQL As String
Dim bWasFilterOn As Boolean

bWasFilterOn = Me.FilterOn

If IsNull(Me.cboFindHH) Then
If Me.RecordSource <> "Families" Then
Me.RecordSource = "Families"
End If
' If the combo is Null, use the whole table as the RecordSource.
Else
strSQL = "SELECT DISTINCTROW Families.* FROM Families " & _
"INNER JOIN Children ON " & _
"Families.ID = Children.ID " & _
"WHERE Children.ID = " & Me.cboFindHH & ";"
Me.RecordSource = strSQL
End If

If bWasFilterOn And Not Me.FilterOn Then
Me.FilterOn = True
End If

Exit_cboFindHH_AfterUpdate:
Exit Sub

Me!cboFindHH.Requery

End Sub

Private Sub cboFindChild_AfterUpdate()
If IsNull(Me.cboFindChild) Then
Me.FilterOn = False
Else
Me.Filter = "ID = " & Me.cboFindChild & ""
Me.FilterOn = True
End If
End Sub

Any help is appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top