How would i print a report based on criteria selected from several
Combo Boxes as well as multiple Multi Select List Boxes, that are
located on the same form?
I can get one Multi List Box, just not several, to report using this
code i found -
Private Sub cmdPreview_Clic k()
On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
'strDelim = """" 'Delimiter appropriate to field type.
See note 1.
strDoc = "Products by Category"
With Me.lstCategory
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varIt em) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) &
""", "
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen 0 Then
strWhere = "[CategoryID] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen 0 Then
strDescrip = "Categories : " & Left$(strDescri p, lngLen)
End If
End If
If CurrentProject. AllReports(strD oc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If
DoCmd.OpenRepor t strDoc, acViewPreview, WhereCondition: =strWhere,
OpenArgs:=strDe scrip
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description , ,
"cmdPreview_Cli ck"
End If
Resume Exit_Handler
End Sub
Any help would be greatly apprciated!
Many thanks
Michael
Combo Boxes as well as multiple Multi Select List Boxes, that are
located on the same form?
I can get one Multi List Box, just not several, to report using this
code i found -
Private Sub cmdPreview_Clic k()
On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
'strDelim = """" 'Delimiter appropriate to field type.
See note 1.
strDoc = "Products by Category"
With Me.lstCategory
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varIt em) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) &
""", "
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen 0 Then
strWhere = "[CategoryID] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen 0 Then
strDescrip = "Categories : " & Left$(strDescri p, lngLen)
End If
End If
If CurrentProject. AllReports(strD oc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If
DoCmd.OpenRepor t strDoc, acViewPreview, WhereCondition: =strWhere,
OpenArgs:=strDe scrip
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description , ,
"cmdPreview_Cli ck"
End If
Resume Exit_Handler
End Sub
Any help would be greatly apprciated!
Many thanks
Michael
Comment