Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Filter records in a subform based on a selection in a forms header combobox

I have a main form and a datasheet subform.  I want to filter records in a subform based on a selection in a forms header combobox.  How can I do this?
ASKER CERTIFIED SOLUTION
Avatar of Jonathan Kelly
Jonathan Kelly
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SteveL13

ASKER

Am getting an error...  "Data type mismatch in criteria experssion"
Using this code:

Private Sub cboClientRecordID_AfterUpdate()
On Error GoTo Err_cboClientRecordID_AfterUpdate

    Me.subfrmScheduleRecordsDS.Form.Filter = "[ClientID] = '" & Me.cboClientRecordID & "'"
    Me.subfrmScheduleRecordsDS.Form.FilterOn = True
    Me.subfrmScheduleRecordsDS.Requery

Exit_cboClientRecordID_AfterUpdate:
    Exit Sub

Err_cboClientRecordID_AfterUpdate:
    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
    Resume Exit_cboClientRecordID_AfterUpdate

End Sub

Open in new window

Got it with:

Private Sub cboClientRecordID_AfterUpdate()
On Error GoTo Err_cboClientRecordID_AfterUpdate

    Me.subfrmScheduleRecordsDS.Form.Filter = "[ClientID] = " & Me.cboClientRecordID
    
    Me.subfrmScheduleRecordsDS.Form.FilterOn = True
    Me.subfrmScheduleRecordsDS.Requery

Exit_cboClientRecordID_AfterUpdate:
    Exit Sub

Err_cboClientRecordID_AfterUpdate:
    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
    Resume Exit_cboClientRecordID_AfterUpdate

End Sub

Open in new window

Great. Well done. You don't need the quotes when passing in a numeric datatype.