Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '3075': Syntax error (missing operator) in query expression 'Birthday = and Birthmonth ='.

Chelu

Technical User
Apr 24, 2025
1
Hi, getting a Run-time error '3075': Syntax error (missing operator) in query expression 'Birthday = and Birthmonth ='.
Probably having to do with spaces but can't see it, any assistance would be greatly appreciated

Function DisplayBirthdayList()

Dim rs As Recordset
Dim sql As String
Dim numberOfBD As Integer
Dim sList As String

sql = "Select * from qryBirthdayList Where Birthday = " & Format(dSelectDate, "dd") & " and Birthmonth = " & Format(dSelectDate, "mm") & ";"

Set rs = CurrentDb.OpenRecordset(sql)

Thanks
 
I would change the code to the following which will possibly show no value for dSelectDate

Code:
Dim rs As DAO.Recordset
Dim sql As String
Dim numberOfBD As Integer
Dim sList As String

sql = "Select * from qryBirthdayList Where Birthday = " & Format(dSelectDate, "dd") & " and Birthmonth = " & Format(dSelectDate, "mm") & ";"
Debug.Print sql   'troubleshoot this SQL
Set rs = CurrentDb.OpenRecordset(sql)
 
The answere is right there in the error message:

query expression 'Birthday = and Birthmonth ='.

For some reason, the Format function must be returning an empty string. Maybe dSelectDate is an empty string. You should probably verify that before you run the query.
 
dhookom and gmmastros are correct.
When I run your code I get the exact same error.
When I add:
Dim dSelectDate As Date
dSelectDate = #11/12/2024#
to your code, sql becomes
SELECT * FROM [qryBirthdayList] WHERE Birthday = 12 AND Birthmonth = 11;
and all is AOK.
So it seems your dselectdate is either not a date, or it's empty.
 

Part and Inventory Search

Sponsor

Back
Top