gojets1721
Registered User.
- Local time
- Today, 10:45
- Joined
- Jun 11, 2019
- Messages
- 430
See the attached example DB. I'm using a unbound form to filter a report. The form has two text fields and a listbox to filter.
I got it working perfectly with only the listbox. When I added in the text fields and associated VBA, I'm now getting a data mismatch error on the openreport line.
I can't seem to figure out what I'm doing wrong. Any suggestions?
Here's the form's code as well:
I got it working perfectly with only the listbox. When I added in the text fields and associated VBA, I'm now getting a data mismatch error on the openreport line.
I can't seem to figure out what I'm doing wrong. Any suggestions?
Here's the form's code as well:
Code:
Private Sub btnOpenReport_Click()
Dim strReportName As String
Dim strReportView As String
Dim strCriteria As String
Dim strSort As String
Dim strDescrip As String
Dim lngLen As Long
Dim varItem As Variant
Dim strDelim As String
Dim db As DAO.Database
Set db = CurrentDb
strDelim = """"
strReportName = "rptComplaints"
strReportView = acViewReport
'Customer First Name
If Not IsNull(Me.txtCustomerFirstName) Then
strCriteria = strCriteria & "([CustomerFirstName] Like ""*" & Me.txtCustomerFirstName & "*"") AND "
End If
'Customer Last Name
If Not IsNull(Me.txtCustomerLastName) Then
strCriteria = strCriteria & "([CustomerLastName] Like ""*" & Me.txtCustomerLastName & "*"") AND "
End If
'Complaint Category
With Me.listComplaintCategory
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strCriteria = strCriteria & strDelim & .ItemData(varItem) & strDelim & ","
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With
lngLen = Len(strCriteria) - 1
If lngLen > 0 Then
strCriteria = "[ComplaintCategory] IN (" & Left$(strCriteria, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If
'Report will not filter if open, so close it.
If CurrentProject.AllReports(strReportName).IsLoaded Then
DoCmd.Close acReport, strReportName
End If
DoCmd.OpenReport strReportName, strReportView, , strCriteria, , strSort
End Sub