Filtering based on two criteria (1 Viewer)

CoffeeLover

New member
Local time
Yesterday, 23:25
Joined
Aug 5, 2015
Messages
6
Hello!
I am having trouble filtering my report.
My goal is to filter the report by:
1) [DateChanged] by user entry on a form (txtFrom and txtTo)
2)[Deliverable] by selection of a list box on form

My error is in the last line when i open the report.
it only lets me filter using either option 1 or 2.
When i include the "And", it gives me the error "Type Mismatch"
I know its a syntax error.

Any help?
Thanks!
My code is below

'''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Deliverable As String
Dim DateChanged As String
Dim VarItm As Variant
For Each VarItm In List2.ItemsSelected
Deliverable = Deliverable & "[ID] = " & List2.Column(0, VarItm) & " OR "
Next
If Deliverable <> "" Then
Deliverable = Left(Deliverable, Len(Deliverable) - 4)
Else
Deliverable = "True"
End If


If Me.txtFrom <> "" Then
DateChanged = "[DateChanged] Between #" & Format(Me.txtFrom, "m/d/yyyy") & _
"# And #" & Format(Me.txtTo + 1, "m/d/yyyy") & "#"
End If
DoCmd.OpenReport "rChangeReport", acViewReport, , Deliverable And DateChanged
 

CoffeeLover

New member
Local time
Yesterday, 23:25
Joined
Aug 5, 2015
Messages
6
I have a list of delivery item in a list box on a form. The user then selects items from the list box that they want to appear on the report.

I'm just having trouble making both filters work at the same time
 

GinaWhipp

AWF VIP
Local time
Today, 02:25
Joined
Jun 21, 2011
Messages
5,899
can't put two Criteria together like that. You actually need to do that first and then put *that* in the Where portion. Something like...

Code:
 Dim Deliverable As String
Dim DateChanged As String
Dim VarItm As Variant
 Dim strWhere As String
 
For Each VarItm In List2.ItemsSelected
strWhere = strWhere & "[ID] = " & List2.Column(0, VarItm) & " OR "
Next
If strWhere <> "" Then
strWhere = Left(strWhere , Len(strWhere ) - 4)
Else
strWhere = "True"
End If


If Me.txtFrom <> "" Then
strWhere = "[strWhere] Between #" & Format(Me.txtFrom, "m/d/yyyy") & _
"# And #" & Format(Me.txtTo + 1, "m/d/yyyy") & "#"
End If

 DoCmd.OpenReport "rChangeReport", acViewReport, , strWhere

I did not test the above, it is an example only because if your Users only select from the List Box you are going to have to strip off the last 5 characters with some like...

Code:
 Dim lngLen As Long
  
 lngLen = Len(strWhere) - 5

You will also have to write something if they want to see all the records.
 

Users who are viewing this thread

Top Bottom