I have a Access Application where I am attempting to filter the records by using a control with VBA code. I am however getting the error "Run-time error '13: Type mismatch" when running the control. The line that has the error is bold and red in the sample. If I recreate the SQL as a query there is no problems and it returns the correct rows from the table.
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 = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'Filter frmCustomers based on search criteria
Form_Frm_Resource.RecordSource = "SELECT Tbl_Resource* FROM Tbl_Resource WHERE (((cboSearchField.Value) Like " * txtSearchString * "))"
Form_Frm_Resource.Caption = "Resources (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSearch"
MsgBox "Results have been filtered."
End If
End Sub