I am trying to adapt an example to filter a form using a second form that collects both a field name (cboSearchField - all options are text controls) and field content (txtSearchString) and passes their contents to:
Private Sub cmdSearch_Click()
If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."
ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
'Generate search criteria
GCriteria = "Replace(" & cboSearchField.Value & ", chr(39), '')" & " LIKE '*" & Replace(txtSearchString, "'", "") & "*'"
'Filter frmPersonalMasterF based on search criteria
** Form_PersonalMasterF.RecordSource = "select * from ContactMasterT where " & GCriteria
Form_PersonalMasterF.Caption = "Customers (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "SearchF"
MsgBox "Results have been filtered."
End If
End Sub
I am getting an error message - Runtime error '3464'Data type mismatch in criteria expression. Debug points to the line marked **. Can anyone see my problem?
Private Sub cmdSearch_Click()
If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."
ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
'Generate search criteria
GCriteria = "Replace(" & cboSearchField.Value & ", chr(39), '')" & " LIKE '*" & Replace(txtSearchString, "'", "") & "*'"
'Filter frmPersonalMasterF based on search criteria
** Form_PersonalMasterF.RecordSource = "select * from ContactMasterT where " & GCriteria
Form_PersonalMasterF.Caption = "Customers (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "SearchF"
MsgBox "Results have been filtered."
End If
End Sub
I am getting an error message - Runtime error '3464'Data type mismatch in criteria expression. Debug points to the line marked **. Can anyone see my problem?