A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Works, But Doesn't Filter



 
 
Thread Tools Display Modes
  #1  
Old May 15th, 2007, 07:46 PM posted to microsoft.public.access.reports
DS
external usenet poster
 
Posts: 285
Default Works, But Doesn't Filter

I have this code from Allen Browne It shows all of the records and won't
filter. This is for filtering a report from a Multi-Select List Box. The
field is a text field. Any help appreciated.
Thanks
DS

Private Sub Command5_Click()
On Error GoTo Err_Handler
Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String

strDelim = """" .
strDoc = "rptDeliveryByStreet"

With Me.ListStreets
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ""
strDescrip = strDescrip & """" & .Column(0, varItem) & """"
End If
Next
End With

If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler
End Sub


  #2  
Old May 15th, 2007, 10:07 PM posted to microsoft.public.access.reports
Duane Hookom
external usenet poster
 
Posts: 7,177
Default Works, But Doesn't Filter

You missed a bunch of his code from http://www.allenbrowne.com/ser-50.html.
This includes the comma separation between items and the lines that reference
the field to compare against the selected items.
--
Duane Hookom
Microsoft Access MVP


"DS" wrote:

I have this code from Allen Browne It shows all of the records and won't
filter. This is for filtering a report from a Multi-Select List Box. The
field is a text field. Any help appreciated.
Thanks
DS

Private Sub Command5_Click()
On Error GoTo Err_Handler
Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String

strDelim = """" .
strDoc = "rptDeliveryByStreet"

With Me.ListStreets
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ""
strDescrip = strDescrip & """" & .Column(0, varItem) & """"
End If
Next
End With

If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler
End Sub



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:40 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.