3075 Syntax error (missing operator) in query expression

G

Guest

The following code is generating this error. It displays the expected
criteria string in the window surrounded by single quotes and parentheses,
like:

'(criteria string)'

I can't figure it out; I'm using the same code elsewhere without issue.
txtLastDate is an unbound textbox assigned in the On Open event to the value
of a Date variable. txtFirstDate is bound to the expression:

=CDate(Month([txtLastDate]) & "/1/" & Year([txtLastDate]))

'Code
' Print monthly PM report
intPrintPMReport = MsgBox("Print monthly PM report?", _
vbOKCancel + vbDefaultButton1, _
"Print Monthly PM Report")
If intPrintPMReport = vbOK Then
strRptName = "MonthlyActivityReportByProjectPM"
strCriteria = "Between #" & Me![txtFirstDate] & _
"# And #" & Me![txtLastDate]
DoCmd.OpenReport strRptName, acViewPreview, , strCriteria
End If

Thank you for any assistance.
Sprinks
 
G

Guest

Hi Sprinks
The criteria need a closing #

strCriteria = "Between #" & Me![txtFirstDate] & _
"# And #" & Me![txtLastDate] & "#"
 
G

Guest

Ofer,

Thank you for your response, however, the problem runs deeper. Adding the
final "#" continued to generate the error. I'd also tried using CDate() to
type the value of each textbox, without the "#" characters; this didn't work
either.

Finally figured out that I never specified a field whose value should be in
the stated range:

strCriteria = "[Workdate] Between #" & Me![txtFirstDate] & _
"# And #" & Me![txtLastDate] & "#"

Best regards.

Sprinks

Ofer Cohen said:
Hi Sprinks
The criteria need a closing #

strCriteria = "Between #" & Me![txtFirstDate] & _
"# And #" & Me![txtLastDate] & "#"


--
Good Luck
BS"D


Sprinks said:
The following code is generating this error. It displays the expected
criteria string in the window surrounded by single quotes and parentheses,
like:

'(criteria string)'

I can't figure it out; I'm using the same code elsewhere without issue.
txtLastDate is an unbound textbox assigned in the On Open event to the value
of a Date variable. txtFirstDate is bound to the expression:

=CDate(Month([txtLastDate]) & "/1/" & Year([txtLastDate]))

'Code
' Print monthly PM report
intPrintPMReport = MsgBox("Print monthly PM report?", _
vbOKCancel + vbDefaultButton1, _
"Print Monthly PM Report")
If intPrintPMReport = vbOK Then
strRptName = "MonthlyActivityReportByProjectPM"
strCriteria = "Between #" & Me![txtFirstDate] & _
"# And #" & Me![txtLastDate]
DoCmd.OpenReport strRptName, acViewPreview, , strCriteria
End If

Thank you for any assistance.
Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top