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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filter report by multiple criteria

Status
Not open for further replies.
Jan 14, 2002
143
US
Hi everybody, I'm having trouble getting a report to filter with two criterias. The following isn't working, but isn't giving an error message either. My second criteria is a date; is there something special I need to know about filtering by a date (or anything else)?

Dim stDocName As String
Dim stCriteria1 as string
Dim stCriteria2 as string

stCriteria1 = "[criteria1]=" & me![criteria1]
stCriteria2 = "[criteria2]=" & me![criteria2]

stDocName = "Concrete Report"
DoCmd.OpenReport stDocName, acNormal, criteria1, stCriteria2





 
Here you go:

Dim stDocName As String
Dim stCriteria as string

' If both criteria are numbers
stCriteria = "[criteria1]=" & criteria1 & " AND " & criteria2

' If both criteria are text
'stCriteria = "[criteria1]='" & criteria1 & "' AND '" & criteria2 & "'"

' If both criteria are dates
'stCriteria = "[criteria1]=#" & criteria1 & "# AND #" & criteria2 & "#"

' If one criteria is text and one is date
'stCriteria = "[criteria1]='" & criteria1 & "' AND #" & criteria2 & "#"


stDocName = "Concrete Report"
DoCmd.OpenReport stDocName, acNormal, ,criteria1

John Ruff - The Eternal Optimist :)
 
1) Dim your second criteria as a DATE, not a string.

2) Concatenate the two - you can only apply one "filter" at a time, but it can be a compound filter

StrCriteria = strCriteria1 & " and [red]>[/red]" & "#" & Criteria2 & "#"

substituting the appropriate logical operator for [red]>[/red]

 
Oops,

Dim stDocName As String
Dim stCriteria as string

' If both criteria are numbers
stCriteria = "[criteria1]=" & criteria1 & " AND [criteria2]=" & criteria2

' If both criteria are text
'stCriteria = "[criteria1]='" & criteria1 & "' AND [criteria2]='" & criteria2 & "'"

' If both criteria are dates
'stCriteria = "[criteria1]=#" & criteria1 & "# AND [criteria2]=#" & criteria2 & "#"

' If one criteria is text and one is date
'stCriteria = "[criteria1]='" & criteria1 & "' AND [criteria2]=#" & criteria2 & "#"


stDocName = "Concrete Report"
DoCmd.OpenReport stDocName, acNormal, ,criteria1
John Ruff - The Eternal Optimist :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top