Hi,
I've been stuck on this error for the last 2 days and I can't seem to figure out what it is that is wrong.
On my initial form, I've used the record source as SELECT * FROM [Legal Files];
However, when doing this, I had to manually write this code in. When I tried to add this code by using the ... I was unable to do so because I would get a "The SELECT statement includes a reserved word or an argument name that is misspelled or missing".
But, by manually writing in that code, my form was able to pick up all the record information correctly.
On my search form, I have this expression for my search button.
Code:
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_FileLookup.RecordSource = "SELECT * FROM [Legal Files] where " & GCriteria
Form_FileLookup.Caption = "[Legal Files] (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "Search"
MsgBox "Results have been filtered."
End If
End Sub
When running the search, I get the syntax error. When debugging, the following code is highlighted.
Code:
Form_FileLookup.RecordSource = "SELECT * FROM [Legal Files] where " & GCriteria
I'm taking this code from a sample template online where the code works, but I can't get it to work on my own database.
If somebody could help me, that would be greatly appreciated.
Thank you.