Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I combine 2 expressions in a where condition paramater

Status
Not open for further replies.

theSizz

Technical User
Apr 22, 2002
93
US
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"

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.

 
You need some brackets, I feel - try:

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"
[pc2]
 
OK,
I got it.

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

No more Type mismatch errors. I didn't have the quotes placed properly around the last AND.

Thanks for the help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top