Multiple reports from a multiple selection of a list

W

Will G

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.
 
A

Allen Browne

Loop through the ItemsSelected collection of the list box.
In the loop, use OpenReport for each.
 
W

Will G

Hey Allen,
any loop sample that you could direct me to, i am very new on this. thanks
again
 
W

Will G

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
 
A

Allen Browne

It seems that your list box has 6 columns.
One of those (the first one?) is the Bound Column (the Value of the list
box.)
If the bound column is the date, use # as the delimiter.
Change the first line after the DIMs to:
strDelim = "#"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Will G said:
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
 
W

Will G

Man, you the best, works perfectly........now i am wondering if you could
help me with something else on the same form.
this is the situation......i am comparing two table and getting the unmatch
data from them in a unmatch query. i am displaying this unmatch data in a
list box on a form and what i want to do is to click on an item from this
list and take me to another form where i build this item and add it to a
table. this is what i have.
tblA
fields: ModelNumber, sizeID, ConfigID, SpringID
tblB
Fields: ModelNumber, date, orderNo

tblA compared to tblB using qrUnmatch to get unmatch ModelNumber data.
formA has a list box row source = qrUnmatch....i want to select a
ModelNumber from the list to take me to formB with ModelNumber populated

formB has row source = tblA....and here is where, i give ModelNumber a Size,
Config, Spring. once ModelNumber is here, should be added into tblA
automatically....Do You understand what i am asking, cause i am a little
comfused myself........am i dreaming or can this be done.....or it's there an
easier way of doing this....Help me please....and thank a lot.

--
need help


Allen Browne said:
It seems that your list box has 6 columns.
One of those (the first one?) is the Bound Column (the Value of the list
box.)
If the bound column is the date, use # as the delimiter.
Change the first line after the DIMs to:
strDelim = "#"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Will G said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top