Dim vnt As Variant
For Each vnt in lst.ItemsSelected
Me.Tag = lst.ItemData(vnt)
DoCmd.OpenReport "rptMyReport", Mode
Next vnt
I use the form's Tag property to pass the name of the current list
item to the report. This works well but the problem is I only get one
report previewed. When the loop does the second OpenReport for the
second selected list box item the OpenReport apparently sees that a
report with the same name is already open so it doesn't open a new
one.
How do I get around this?
TIA :)
Dim vnt As Variant
TIA :) "
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
What you need to do is open a single instance of the report for each
ItemDate in the list box's ItemsSelected collection. Here's how.
<-- VBA code snippet -->
Option Compare Database
Option Explicit
' Create a collection in the declarations section of the module
' You will store the references to the objects (the reports) so they
' don't disappear until you're ready for them to disappear.
Dim myReports As New Collection
' This sub creates an instance of the report for each ItemData.
' The "item as variant" is item of lst.ItemDate(vnt).
Sub newReport(item as variant)
' Here is where you create the new instance of the report.
' The format Report_rptMyReport has to match your report's name.
' For example: If your report name was "rptMonthlyAccounts" the Dim
' statement would be Dim rpt as New Report_rptMonthlyAccounts
Dim rpt As New Report_rptMyReport
' I'd suggest you make a module variable in the report's module
' declarations with a name similar to (below) and stuff the item in that
' way; instead of using the calling form's .Tag property (each iteration
' of the "For...each" loop would obliterate the last item before the
report
' got it otherwise).
rpt.m_ListBoxItem = item
' So the user can see the results.
rpt.Visible = True
' Next place a reference to the report in this module's collection - so
' the report won't disappear when this sub ends.
myReports.Add rpt, rpt.Hwnd & ""
End Sub
' This is an example of a sub which you would call after all the
' reports are printed. It clears out the holding collection so there
' aren't any stray object references floating around taking up memory.
' If this sub was called before the report was printed - the report
' would not be printed - it would disappear.
Sub cleanReports()
Dim rpt As Variant
' If the report is no longer in the collection ignore errors.
On Error Resume Next
For Each rpt In myReports
myReports.Remove 1
Next
End Sub
<-- End VBA code snippet -->
You would have to change your For Each loop to:
Dim vnt As Variant
For Each vnt in lst.ItemsSelected
Call newReport( lst.ItemData(vnt) )
Next vnt
Hope this helps.
- --
M. G. Foster:::mgf
Oakland, CA (USA)
=========================================================
NB: To respond by Email remove 'Higgley' from my address.
=========================================================
PGP key server =
<http://swissnet.ai.mit.edu:11371/pks/lookup?op=get&search=0x46811150>
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBNRJFrQPchIhGgRFQEQIm/QCfT+ICEUhUEpARc0mc3demQj99bVgAnjcI
t8m42GX61kYnxlSWFLh2kYZO
=9/7B
-----END PGP SIGNATURE-----