Results 1 to 3 of 3
  1. #1
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313

    Multiple Print Previews at One Time


    I have a database with several places an operator may request print previews. Currently, if an operator runs a print preview (my VBA code is docmd.OpenReport "Report Name", acPreview), the report opens in preview mode and the operator may view it. However, if the operator leaves the preview on the screen and selects another tab and requests another print preview with the same report name, but different selection criteria, the first preview remains unchanged and the second one doesn't appear. I would like it to open in a separate window so the operator may toggle between the preview windows to see both reports. Thanks, Eddie

  2. #2
    randman1 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    25
    I found multiple report instancing to be a difficult task but even more difficult was supplying each instance with different criteria. Creating multiple instances involves declaring a new instance of the report rather than using the DoCmd.OpenReport method. For example

    Code:
    Private moReport as Report
    Private moReportsCollection as New Collection
    
    Private Sub ShowReport(sReportName As String)
        
        Select Case sReportName
            Case "rptReport1"
                Set moReport = New Report_rptReport1
             
            Case "rptReport2"
                Set moReport = New Report_rptReport2
    
            Case Else
                MsgBox "Invalid Report Name"
        End Select
    
        moReport.Visible = True
        moReportsCollection.Add
    End Sub
    When you use this method however, you cannot use OpenArgs to supply criteria to the report. My solution was to have each report determine if it was opening without supplied criteria. If criteria was not supplied, the report looks at a Report Wizard public property to verify that a user clicked a Preview button (this prevents the report from being opened from the database window without any criteria). The public property is called Params and is a collection of criteria and other parameters used by the report. Here's the code from one report.

    Code:
    Option Compare Database
        
    Private msCriteria As String
    Private msReportID As String
    
    Private Sub Report_Open(Cancel As Integer)
        'This report gets selected criteria from the Report Wizard.
        'It cannot be opened directly from the database window.
        'The Report Wizard has a public propertiey named Params
        'that contains criteria statements and a human readable form of the criteria.
        Dim oWizard As Form_frmRnmReportWizard
        Dim sPrompt As String
        
        If msCriteria = "" Then
            'No criteria is specified. Look to Report Wizard for report criteria.
            If CurrentProject.AllForms("frmRnmReportWizard").IsLoaded Then
                'Report Wizard is open. Ensure that this report has permission to open.
                'Permission is granted if this report is currently selected and user had clicked Preview
                Set oWizard = Form_frmRnmReportWizard
                If oWizard.OpenPermission(Me.Name) = True Then
                    msCriteria = oWizard.Params("WhereSql")
                    Me.RecordSource = "SELECT * FROM qryRnmTrapGroups_XField " & _
                        "WHERE " & msCriteria
                    
                    'Add taskbar button for popup form
                    SetWindowLong Me.hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW
                    Call SetImage("imgTitlePage", "TitlePageImage")
                    Call SetImage("imgPageHeader", "PageHeaderImage")
                    msReportID = DateDiff("s", 0, Now)
                    Me.txtReportID = msReportID
                    Me.Caption = "RNM Traps Daily Totals - " & msReportID
                    Me.txtCriteriaText = "Selected criteria for report ID " & msReportID & ":" & _
                        vbCrLf & oWizard.Params("WhereText")
                    
                    'Once this report opens from the Report Wizard, the Open event is triggered.
                    'The Report Wizard uses this event to set the OpenPermission property to False
                Else
                    sPrompt = "Use the Report Wizard to open reports"
                    MsgBox sPrompt
                    Cancel = True
                End If
            Else
                'Report Wizard is not open. Open the Wizard and close this report.
                Cancel = True
                DoCmd.OpenForm FormName:="frmRnmReportWizard", OpenArgs:=Me.Name
            End If
        End If
        
    End Sub
    There's more to this such as the different criteria collection forms and the way that the Report Wizard calls the BuildCriteria sub of each. I can post more details if you want to explore this route.

  3. #3
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313
    The solution you provided works great. I don't have any OpenArgs parameters, so I simply checked to see if the report is loaded and, if so, change the report string to "Report2" or "Report3", etc. Thanks for your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-14-2011, 09:16 AM
  2. Multiple Pages Print
    By gmitchell@exbrief.com in forum Forms
    Replies: 1
    Last Post: 01-23-2011, 06:06 PM
  3. Replies: 10
    Last Post: 11-23-2010, 10:16 PM
  4. Replies: 1
    Last Post: 11-05-2010, 03:48 PM
  5. Replies: 0
    Last Post: 10-04-2008, 07:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums