Where condition in OpenReport argument

scottb
4StarLounger
Posts: 402
Joined: 14 Apr 2010, 15:59

Where condition in OpenReport argument

Post by scottb »

Hello,
I am trying to open a report from a form with a where condition that will match ProjectID to ProjectID AND ActionItemType (field name on the report) = "Risk". Opening to the projectID works fine. I am trying to add the condition for [ActionItemType]="Risk" and I receive and error "Can't find the field '1' referred to in your expression" when I try the following:

DoCmd.OpenReport "rptProjectActionItems", acViewReport, "", "[ProjectID]=" & ProjectID And "Risk=" & [ActionItemType], acNormal

I have been unable to find an example with two where conditions to obtain the correct syntax.
Any help would be appreciated.
Thank you very much.
-Scott

User avatar
HansV
Administrator
Posts: 78439
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Where condition in OpenReport argument

Post by HansV »

The word And should be within the quotes:

Code: Select all

DoCmd.OpenReport "rptProjectActionItems", acViewReport, , "ProjectID=" & Me.ProjectID & " And Risk=" & Me.ActionItemType
Or is ActionType the field name and should its value be the word "Risk"? If so:

Code: Select all

DoCmd.OpenReport "rptProjectActionItems", acViewReport, , "ProjectID=" & Me.ProjectID & " And ActionType='Risk'"
Best wishes,
Hans

scottb
4StarLounger
Posts: 402
Joined: 14 Apr 2010, 15:59

Re: Where condition in OpenReport argument

Post by scottb »

DoCmd.OpenReport "rptProjectActionItems", acViewReport, , "ProjectID=" & Me.ProjectID & " And ActionType='Risk'" did what I was hoping.
Once again thank you for your help.