How do I combine 2 expressions in a where condition paramater

theSizz

Registered User.
Local time
Today, 21:40
Joined
Nov 29, 2002
Messages
34
I'm using the DoCmd.OpenReport method. A portion of my code looks like this:

Dim ReportName, DateFieldName, CatCriteria

DateFieldName = "DelivDate"
ReportName = "rptInvoices"
CatCriteria = "meat > 0"

DoCmd.OpenReport _
ReportName:=ReportName, _
view:=Me.OutputMode, _
wherecondition:=DateFieldName & " Between #" & _
Me.StartDate & "# AND #" & _
Me.EndDate & "#" And "& CatCriteria"

The problem is with the wherecondition clause.
When I try to run the code I get a Type Mismatch error. If I run the code with either of the expressions it runs fine the problem exists when I combine the 2 expressions. I know it must be a problem with my syntax but I can't figure it out. Can anyone please help me ? CatCriteria is a field type number and obviously DelivDate is a field type date. Me.StartDate and Me.EndDate are unbound controls on a form that the user supplies dates to. What I am trying to do is select invoices between certain dates when a specified field is > 0.
Thanks for any help offered.
 
Code:
Dim ReportName, DateFieldName, CatCriteria

DateFieldName = "DelivDate"
ReportName = "rptInvoices"
CatCriteria = "meat > 0"

DoCmd.OpenReport _
ReportName:=ReportName, _
View:=Me.OutputMode, _
wherecondition:=DateFieldName & " Between #" & _
Me.StartDate & "# AND #" & _
Me.EndDate & "#" & " AND " & "& CatCriteria"

This should work now. You hadnt got the second "AND" enclosed in quotes so it was being picked up as a keyword rather than a string.

HTH,
Patrick
 
Thanks Patrick,
That was it.
The code is as follows:
DoCmd.OpenReport _
ReportName:=ReportName, _
view:=Me.OutputMode, _
wherecondition:=DateFieldName & " Between #" & _
Me.StartDate & "# AND #" & _
Me.EndDate & "#" & " AND " & CatCriteria

We don't need the quotes around CatCriteria it produces a syntax error. Thanks for steering me in the right direction, now I can get some sleep it's 2:30 a.m. in Los Angeles and this has kept me up all night. Thanks again for the help.
 

Users who are viewing this thread

Back
Top Bottom