Hey Allen, i found your directory with some sample and it works perfectly,
however, i like have the criteria type date and it seems like i am doing
something wrong. can you check out the code for me and spot what i am
doing
wrong. i like set the criteria to RequiredDate(Type Date) and OrderNo(type
Double). this is what i have. Your code below works with string fields,
but
not with date or double.
here is my RowSource for MyList
SELECT [qrProduction].[RequiredDate], [qrProduction].[OrderNo],
[qrProduction].[ID], [qrProduction].[ID_1], [qrProduction].[Description],
[qrProduction].[OrderQty] FROM [qrProduction] ORDER BY
[qrProduction].[RequiredDate] AND [qrProduction].[OrderNo];
On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the list
box.
'Author: Allen J Browne, 2004.
http://allenbrowne.com
Dim varItem As Variant 'Selected items
Dim strWhere As Date '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.
Dim strLabel As String
'strDelim = """" 'Delimiter appropriate to field type. See
note 1.
strDoc = "rptProduction"
'strLabel = "rptProductionLabel"
'Loop through the ItemsSelected in the list box.
With Me.sched
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
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
'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[RequiredDate] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 4
If lngLen > 0 Then
strDescrip = "Production Required: " & Left$(strDescrip,
lngLen)
End If
End If
'Report will not filter if open, so close it. For Access 97, see note
3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.close acReport, strDoc
End If
'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
'DoCmd.OpenReport strLabel, 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, ,
"PrintMultRpt_Click"
End If
Resume Exit_Handler
--
need help
Will G said:
Hey Allen,
any loop sample that you could direct me to, i am very new on this.
thanks
again
--
need help
:
Loop through the ItemsSelected collection of the list box.
In the loop, use OpenReport for each.
I have a multiple selection list and for each item selected i like to
printPriview a report. i could preview the report from one item from
the
list
only, but not for multiple selection. i hope there is someone here
that
could
help me out with this.