Dynamic List Box for Printing/Previewing Reports

G

Guest

I wrote some code (OK, I admit I copied the code from "Beginning Access 2000
VBA"). It works great, but I want to take it one step further and so far no
luck. Here's what I've got:

I've got a form called frmReportList with a list box called lstReports and 2
buttons, cmdPrint and cmdPreview. The list box is populated during form load
with this code:

Private Sub Form_Load()
Dim objAO As AccessObject
Dim objCP As Object
Dim strValues As String

Set objCP = Application.CurrentProject

For Each objAO In objCP.AllReports
strValues = strValues & objAO.Name & ";"
Next objAO

lstReports.RowSourceType = "Value List"
lstReports.RowSource = strValues

End Sub

I've got this procedure that checks to see if a report name is selected:

Private Sub ProcessReport(intAction As Integer)

If Not IsNull(lstReports) Then
DoCmd.OpenReport lstReports, intAction

End If

End Sub

And finally, when the command buttons are clicked, it fires one of these
lines of code:

Private Sub cmdPreview_Click()

ProcessReport acViewPreview

End Sub

OR

Private Sub cmdPrint_Click()

ProcessReport acNormal

End Sub

Everything is great up until this point. What I would like to do it change
the Multi Select property of lstReports to Extended, giving me the ability to
select multiple reports from lstReports and Print or Preview them. I having
trouble writing the code to work with my existing code to make this work.
Any ideas?
 
D

Dan Artuso

Hi,
Here is the loop you need to process each report name:

Dim varReport As Variant

For Each varReport In Me.lstFields.ItemsSelected
MsgBox Me.lstFields.ItemData(varReport)
Next

Just substitute the name of your list box.

When you've verified that the selected names are indeed being displayed by
the MsgBox, comment that line out and put in:

DoCmd.OpenReport Me.lstFields.ItemData(varReport), intAction
 

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