Syntax Error

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?
 
K

Klatuu

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

It should be:

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

RonaldoOneNil

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

Klatuu

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?
 
M

Momof2

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?
 

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

Similar Threads


Top