Help with "Syntax Error Comma in Query Expression

I am trying to run a DoCmd.OpenReport for a command button click:

 

DoCmd.OpenReport "ReportName", acViewPreview, , "[FIELD_NAME]=" & Me![ComboBoxSelection], acWindowNormal

I get the Syntax Error (Comma) in Query Expression with the Combo Box Selection equal to Last Name, First Name. Is there a way to rectify this?

 

Question Info


Last updated November 7, 2018 Views 3,982 Applies to:
Answer
"alepak" wrote in message
news:*** Email address is removed for privacy ***...
>I am trying to run a DoCmd.OpenReport for a command button click:
>
>
>
> DoCmd.OpenReport "ReportName", acViewPreview, , "[FIELD_NAME]=" &
> Me![ComboBoxSelection], acWindowNormal
>
> I get the Syntax Error (Comma) in Query Expression with the Combo Box
> Selection equal to Last Name, First Name. Is there a way to rectify this?
>
 You need to enclose the name field in quotes:
 
'
   DoCmd.OpenReport "ReportName", _
       acViewPreview, , _
       "[FIELD_NAME]=""" & Me![ComboBoxSelection] & """", _
       acWindowNormal
'
 The doubled-up quotes are required to get a double-quote (") inside a quoted
literal.
 
 

Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html
Dirk Goldgar, MS Access MVP 2001-2015
Access tips: www.datagnostics.com/tips.html

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.