Quotation Marks in Strings

M

MoonBlosm

I am trying to print a report using two different critera. This is what I
have but something is wrong:
I am sure it has something to do with the quotes....


stLinkCriteria = "[ProjectID] = " & PreviewProject & And &"[WorkOrder#] =" _
&WorkOrderNum
stDocName = "RptWOChecklist"

DoCmd.OpenReport stDocName, acViewPreview, stLinkCriteria

Thanks in advance!
 
J

John Spencer

stLinkCriteria = "[ProjectID] = " & PreviewProject & " And [WorkOrder#] ="
& WorkOrderNum
stDocName = "RptWOChecklist"

That works if ProjectID and WorkOrder# are number fields. If they are text
fields then you need to add in text delimiters.

stLinkCriteria = "[ProjectID] = '" & PreviewProject & "' And [WorkOrder#]
='" & WorkOrderNum & "' "

Or use the CHR function to add in quotation marks (")

stLinkCriteria = "[ProjectID] = " & Chr(34) & PreviewProject & Chr(34) & "'
And [WorkOrder#] ='" & Chr(34) & WorkOrderNum & Chr(34)

Or use two Quotation marks in each place you need a quotation mark to appear
in the string.

stLinkCriteria = "[ProjectID] = """ & PreviewProject & """ And [WorkOrder#]
=""" & WorkOrderNum & """ "
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
K

Klatuu

John gave you good answers; however, there is still one syntax problem. The
Where argument is the 4th argument. Should be:
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
 
M

MoonBlosm

Thanks, the code is going through now where it stopped before, but it is not
giving me the specific workorder. It gives me all the workorders for that
particular ProjectID.

Any clues?


John Spencer said:
stLinkCriteria = "[ProjectID] = " & PreviewProject & " And [WorkOrder#] ="
& WorkOrderNum
stDocName = "RptWOChecklist"

That works if ProjectID and WorkOrder# are number fields. If they are text
fields then you need to add in text delimiters.

stLinkCriteria = "[ProjectID] = '" & PreviewProject & "' And [WorkOrder#]
='" & WorkOrderNum & "' "

Or use the CHR function to add in quotation marks (")

stLinkCriteria = "[ProjectID] = " & Chr(34) & PreviewProject & Chr(34) & "'
And [WorkOrder#] ='" & Chr(34) & WorkOrderNum & Chr(34)

Or use two Quotation marks in each place you need a quotation mark to appear
in the string.

stLinkCriteria = "[ProjectID] = """ & PreviewProject & """ And [WorkOrder#]
=""" & WorkOrderNum & """ "
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

MoonBlosm said:
I am trying to print a report using two different critera. This is what I
have but something is wrong:
I am sure it has something to do with the quotes....


stLinkCriteria = "[ProjectID] = " & PreviewProject & And &"[WorkOrder#] ="
_
&WorkOrderNum
stDocName = "RptWOChecklist"

DoCmd.OpenReport stDocName, acViewPreview, stLinkCriteria

Thanks in advance!
 
M

MoonBlosm

Nevermind, after reading Klatuu's comment, it is working.

You guys are sanity savers! Thanks for being here and thanks for being
patient with all of us who are learning!

Klatuu said:
John gave you good answers; however, there is still one syntax problem. The
Where argument is the 4th argument. Should be:
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

--
Dave Hargis, Microsoft Access MVP


MoonBlosm said:
I am trying to print a report using two different critera. This is what I
have but something is wrong:
I am sure it has something to do with the quotes....


stLinkCriteria = "[ProjectID] = " & PreviewProject & And &"[WorkOrder#] =" _
&WorkOrderNum
stDocName = "RptWOChecklist"

DoCmd.OpenReport stDocName, acViewPreview, stLinkCriteria

Thanks in advance!
 
J

John Spencer

Thanks for the backup. I should have noted that the argument was in the
wrong place.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Klatuu said:
John gave you good answers; however, there is still one syntax problem.
The
Where argument is the 4th argument. Should be:
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

--
Dave Hargis, Microsoft Access MVP


MoonBlosm said:
I am trying to print a report using two different critera. This is what
I
have but something is wrong:
I am sure it has something to do with the quotes....


stLinkCriteria = "[ProjectID] = " & PreviewProject & And &"[WorkOrder#]
=" _
&WorkOrderNum
stDocName = "RptWOChecklist"

DoCmd.OpenReport stDocName, acViewPreview, stLinkCriteria

Thanks in advance!
 

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