Print Reports Chosen From Listbox

golfnutt8

New member
Local time
Today, 04:17
Joined
Jan 31, 2007
Messages
4
Hello,

I have two list boxes
The first list box shows the available reports that I can chose from.
The second list box will hold the reports that I have chosen from the first list box.
I have a button where I want to print the reports that have been chosen from the second list box.

If I chose one report from the second list box it works but if I chose more than one it doesnt.
I step through the code and it looks like it sees the reports as expected but it only prints the first one in the chosen list. :confused:


Here is the code for the buttons click event.

Private Sub CmdPreviewReports_Click()

Dim i As Integer
Dim strRepName As String

With Me.LstChosenReports
If (.ItemsSelected.Count > 0) Then
For i = 0 To .ListCount - 1
If .Selected(i) Then
If Not IsNull(.ItemData(i)) Then
'DoCmd.SetWarnings False
strRepName = Me.LstChosenReports.Column(0)
DoCmd.OpenReport strRepName, acViewPreview
'DoCmd.SetWarnings True
End If
End If
Next i
Else
MsgBox "You must chose at least one report to print"
Me.LstChosenReports.SetFocus
End If
End With
End Sub
 
Greetings fellow golfer!

When you set the variable for the report name, you aren't using the variable that tells it the current item in the listbox (i).
 
Hi Paul,
Yes, I saw that.
Here is the updated code with some extra tweaks

Private Sub CmdPreviewReports_Click()

Dim iRow As Integer
With Me.LstChosenReports
If (.ListCount > 0) Then
For iRow = 0 To .ListCount - 1
If .Selected(iRow) Then
If Not IsNull(LstChosenReports.ItemData(iRow)) Then
DoCmd.OpenReport Me.LstChosenReports.Column(0, iRow), acViewPreview
End If
End If
Next iRow
Me.SetFocus
DoCmd.Close
Else
MsgBox "You must chose at least one report to print"
Me.LstChosenReports.SetFocus
End If

End With
End Sub
 
So it's working now?
 
Question: How did you create a list box of available reports? I would like to do the same thing except maybe have one list box to select a report and then a command button to preview the report. Ken
 

Users who are viewing this thread

Back
Top Bottom