Quotation Marks in Strings

  • Thread starter Thread starter MoonBlosm
  • Start date Start date
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!
 
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
..
 
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
 
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!
 
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!
 
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!
 
Back
Top