Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103

    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?
    Last edited by JamesB; 07-30-02 at 10:16.

  2. #2
    Join Date
    Jul 2002
    Location
    Alexandria, VA (DC Metro Area)
    Posts
    5
    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.

    Don't know if this will help, but good luck!

  3. #3
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103
    Thank you SW. Your suggestion worked and I'll keep that in mind going forward!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •