Run-time error 3075 Syntax error in query expression (1 Viewer)

ijaz196

Registered User.
Local time
Today, 08:25
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
 

arnelgp

error reading drive A:
Local time
Today, 11:25
Joined
May 7, 2009
Messages
11,147
enclose Teacher ID in square bracket:
Code:
Task = "SELECT * FROM Teacher_Fine WHERE (([COLOR="Blue"][Teacher ID][/COLOR] Like ""*" & strsearch & "*""))"
 

ijaz196

Registered User.
Local time
Today, 08:25
Joined
Dec 29, 2017
Messages
22
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.
 

arnelgp

error reading drive A:
Local time
Today, 11:25
Joined
May 7, 2009
Messages
11,147
is your table Teacher_Fine available?
 

ijaz196

Registered User.
Local time
Today, 08:25
Joined
Dec 29, 2017
Messages
22
yes I have a query named Teacher_Fine which is available
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:25
Joined
Oct 29, 2018
Messages
13,739
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.
 

arnelgp

error reading drive A:
Local time
Today, 11:25
Joined
May 7, 2009
Messages
11,147
on post #3, is this an error:

...SELECT *FROM

there should be a space between the asterisk and FROM.
 

ijaz196

Registered User.
Local time
Today, 08:25
Joined
Dec 29, 2017
Messages
22
No there is already a space in asterisk and FROM
 

arnelgp

error reading drive A:
Local time
Today, 11:25
Joined
May 7, 2009
Messages
11,147
check the spelling, copy the query name from navigation panel and paste it to your vba.
 

ijaz196

Registered User.
Local time
Today, 08:25
Joined
Dec 29, 2017
Messages
22
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.
 

ijaz196

Registered User.
Local time
Today, 08:25
Joined
Dec 29, 2017
Messages
22
Thanks a lot for giving me your prsious time
Now the code is working
Thanks again-
 

Users who are viewing this thread

Top Bottom