If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Unanswered: VBA code to print multiple reports.

I have a form with five reports listed and five corresponding check boxes. Using VBA, I'd like to allow the user to print one or more of the selected reports. I created the following If.......then statements:

If Me.Report1 = True Then
DoCmd.OpenReport "Rpt1", PrintMode
End If
If Me.Report2 = True Then
DoCmd.OpenReport "Rpt2", PrintMode
End If
If Me.Report3 = True Then
DoCmd.OpenReport "Rpt3", PrintMode
End If
If Me.Report4 = True Then
DoCmd.OpenReport "Rpt4", PrintMode
End If
If Me.Report5 = True Then
DoCmd.OpenReport "Rpt5", PrintMode
End If

Unfortunately, if Report2 and Report4 are selected (True), the code stops after the first condition is met yeilding only Report2. Is there another way to approach this?

The code, as you had it typed, should work for your purposes. The only thing that I can think of is that you may have an extra if..then statement floating around somewhere that's causing trouble. Try restructuring what you've got into something like this:

If Me.Report1 = True Then DoCmd.OpenReport "Rpt1", PrintMode

If Me.Report2 = True Then DoCmd.OpenReport "Rpt2", PrintMode

If Me.Report3 = True Then DoCmd.OpenReport "Rpt3", PrintMode

If Me.Report4 = True Then DoCmd.OpenReport "Rpt4", PrintMode

If Me.Report5 = True Then DoCmd.OpenReport "Rpt5", PrintMode

If you only have one action to be performed when your if...then statement is true, then you can put the action on the same line, and skip the End If.