Run-time error 3075 Syntax error in query expression

ijaz196

Registered User.
Local time
Today, 22:43
Joined
Dec 29, 2017
Messages
22
I have a form Named Teacher_Fine which contains the following fields:
Teacher ID
TeachFine_ID
Date
Absent Late

When I put Teacher ID in the search box and click search it shows this error:

"Run-time error 3075 Syntax error (missing operator) in query expression '((Teacher ID Like "*2*"))'

I use the following VBA Code which I get from youtube:

Private Sub Command15_Click()
Dim strsearch As String
Dim Task As String
'Check if a keyword entered or not
If IsNull(Me.TxtSearch) Or Me.TxtSearch = "" Then
MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
Me.TxtSearch.BackColor = vbYellow
Me.TxtSearch.SetFocus
Else
strsearch = Me.TxtSearch.Value
Task = "SELECT * FROM Teacher_Fine WHERE ((Teacher ID Like ""*" & strsearch & "*""))"
Me.RecordSource = Task
Me.TxtSearch.BackColor = vbWhite
End If
End Sub

Kindly help me anyone in this regard that, where I missing something?

Regards
 
enclose Teacher ID in square bracket:
Code:
Task = "SELECT * FROM Teacher_Fine WHERE (([COLOR="Blue"][Teacher ID][/COLOR] Like ""*" & strsearch & "*""))"
 
Mr. arnelgp
Thanks a lot for the reply but the following error appears:

"The record source 'SELECT *FROM Teacher_Fine WHERE (([Teacher ID] Like "*2*"))' specified on this form or report does not exist.
 
is your table Teacher_Fine available?
 
yes I have a query named Teacher_Fine which is available
 
Mr. arnelgp
Thanks a lot for the reply but the following error appears:

"The record source 'SELECT *FROM Teacher_Fine WHERE (([Teacher ID] Like "*2*"))' specified on this form or report does not exist.

Hi. Not sure if it's just a typo, but you're missing a space between * and FROM.
 
on post #3, is this an error:

...SELECT *FROM

there should be a space between the asterisk and FROM.
 
No there is already a space in asterisk and FROM
 
check the spelling, copy the query name from navigation panel and paste it to your vba.
 
Run-time error 2580 is displayed with the following statement

"The record source 'SELECT *FROM Teacher_Fine WHERE (([Teacher ID] Like "*2*"))' specified on this form or report does not exist.
 
Thanks a lot for giving me your prsious time
Now the code is working
Thanks again-
 

Users who are viewing this thread

Back
Top Bottom