I have a query that returns a list of zip codes in a text box in a form. Now I would like to use the list of zip codes in the text box to filter a report to generate a list of all customers within the corresponding zip codes.
When I run the script I get
""438 - Object doesn't support this property or method"
The text in red is where it is highlighted when I debug.
The Name of the text box is txZips
Some imparted knowledge would be greatly appreciated
Private Sub cmdPreview_Click()
'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working.
Dim strReport As String
Dim varItem As Variant
Dim strWhere As String
Dim lngView As Long
strReport = "rptCustomers"
lngView = acViewPreview
varItem = txtZips
strWhere = "1=1"
'
For Each varItem In Me!txtZips.ItemsSelected
strWhere = strWhere & "[ZIP_CODE] Like " & Chr(34) & Me!txZips.Column(0, varItem) & Chr(34) & " or "
Next varItem
On Error Resume Next
strWhere = Left(strWhere, Len(strWhere) - 4)
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
'Open the report.
Debug.Print strWhere
DoCmd.OpenReport strReport, lngView, , strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
End If
Resume Exit_Handler
When I run the script I get
""438 - Object doesn't support this property or method"
The text in red is where it is highlighted when I debug.
The Name of the text box is txZips
Some imparted knowledge would be greatly appreciated

Private Sub cmdPreview_Click()
'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working.
Dim strReport As String
Dim varItem As Variant
Dim strWhere As String
Dim lngView As Long
strReport = "rptCustomers"
lngView = acViewPreview
varItem = txtZips
strWhere = "1=1"
'
For Each varItem In Me!txtZips.ItemsSelected
strWhere = strWhere & "[ZIP_CODE] Like " & Chr(34) & Me!txZips.Column(0, varItem) & Chr(34) & " or "
Next varItem
On Error Resume Next
strWhere = Left(strWhere, Len(strWhere) - 4)
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
'Open the report.
Debug.Print strWhere
DoCmd.OpenReport strReport, lngView, , strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
End If
Resume Exit_Handler