Syntax Error

  • Thread starter Thread starter Momof2
  • Start date Start date
M

Momof2

I am using the following expression:
Dim strWhere As String
strWhere = "[Contractor] = " & Me.Contractor
DoCmd.OpenReport "MissingReceiptReport", acViewPreview, , strWhere

when I go to run my report I get this error:
Syntax Error (missing operator) in query expression '([Contractor] =
Doe, Joe)'

Any ideas on how to make this work?
 
Your code is structured as if [Contractor] were a numeric field.

It should be:

strWhere = "[Contractor] = """ & Me.Contractor & """"
 
Beacuse Contractor is a string you need to surround it with single quotes
strWhere = "[Contractor] = '" & Me.Contractor & "'"
 
Single quotes can be a problem. If the the Contractors name is O'Reilly
you will for sure have a problem.

I know that trying to get the correct number of quotes in a string can be a
problem, so I can up with a "cheater way" to do it.
Go ahead and write the line with single quotes, then go back and replace
each single qoute with two double qoutes.

singles v v
strWhere = "[Contractor] = '" & Me.Contractor & "'"

Changed to 2 doubles v v
strWhere = "[Contractor] = """ & Me.Contractor & """"




RonaldoOneNil said:
Beacuse Contractor is a string you need to surround it with single quotes
strWhere = "[Contractor] = '" & Me.Contractor & "'"

Momof2 said:
I am using the following expression:
Dim strWhere As String
strWhere = "[Contractor] = " & Me.Contractor
DoCmd.OpenReport "MissingReceiptReport", acViewPreview, , strWhere

when I go to run my report I get this error:
Syntax Error (missing operator) in query expression '([Contractor]
=
Doe, Joe)'

Any ideas on how to make this work?
 
Thank you for all your help it finally works!

Klatuu said:
Your code is structured as if [Contractor] were a numeric field.

It should be:

strWhere = "[Contractor] = """ & Me.Contractor & """"

Momof2 said:
I am using the following expression:
Dim strWhere As String
strWhere = "[Contractor] = " & Me.Contractor
DoCmd.OpenReport "MissingReceiptReport", acViewPreview, , strWhere

when I go to run my report I get this error:
Syntax Error (missing operator) in query expression '([Contractor] =
Doe, Joe)'

Any ideas on how to make this work?
 
Back
Top