none
How to stagger windows opened by multiple report previews RRS feed

  • Question

  • I have a command button that opens several reports in Preview Mode . . . by default (I guess), they stack on top of each other . . is there a way to open the Preview, then offset the next Preview windows so they don't overlay each other?
    Friday, September 13, 2019 5:38 PM

Answers

  • You could try the following code in a Public Function after all reports have been opened.

    Dim ActiveReport As AccessObject

    Dim Active As Report
    Dim Position As Integer
    For Each ActiveReport In Application.CurrentProject.AllReports
        With ActiveReport
            If .IsLoaded Then
                Set Active = Screen.ActiveReport
                With Active
                    DoCmd.SelectObject acReport, ActiveReport.Name
                    DoCmd.MoveSize 0, 1200 'Move window down 1200 twisps
                    Position = Active.WindowLeft
                    DoCmd.MoveSize Position + 1000
                End With
            End If 'Loaded
        End With 'Active Report
    Next ActiveReport

    • Marked as answer by Big Itch Saturday, September 14, 2019 3:35 PM
    Friday, September 13, 2019 6:03 PM
  • Hi Big

    You go this way too.

    File / Options / Current database. The "tabbed documents" setting.


    Cheers // Peter Forss Stockholm


    • Edited by ForssPeterNova Friday, September 13, 2019 6:16 PM
    • Marked as answer by Big Itch Saturday, September 14, 2019 3:36 PM
    Friday, September 13, 2019 6:13 PM
  • The following is a function which does this for multiple instances of a form.  You could try doing similarly by calling the MoveSize method of the DoCmd object, either in a loop as below, or after the code to open each form if this is done consecutively rather than in a loop:

    Function StackCompanyForms()

        Const conSQL = "SELECT * FROM Companies Order By Company"

        Dim dbs As DAO.Database, rst As DAO.Recordset
        Dim n As Integer

        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset(conSQL)
        
        Do While Not rst.EOF
           n = n + 1
           Set frm = New Form_frmCompanies
           colPopups.Add frm, frm.hwnd & ""
           frm.Caption = rst.Fields("Company")
           frm.Filter = "CompanyID = " & rst.Fields("CompanyID")
           frm.FilterOn = True
           frm.Visible = True
           DoCmd.MoveSize n * 360, n * 360
           rst.MoveNext
        Loop
        
    End Function

    So, if opening the reports are opened consecutively rather than in a loop the code would be along these lines:

        Dim n As Integer
        n = 1
        
        DoCmd.OpenReport "FirstReportName", acViewPreview
        DoCmd.MoveSize n * 360, n * 360
        n = n + 1
        
        DoCmd.OpenReport "SecondReportName", acViewPreview
        DoCmd.MoveSize n * 360, n * 360
        n = n + 1
        
        ' and so on

    Experiment with the value to which n is initialised and the factor (in twips) by which it is incremented to get the best fit.

    Ken Sheridan, Stafford, England

    • Marked as answer by Big Itch Saturday, September 14, 2019 3:36 PM
    Saturday, September 14, 2019 12:14 PM

All replies

  • You could try the following code in a Public Function after all reports have been opened.

    Dim ActiveReport As AccessObject

    Dim Active As Report
    Dim Position As Integer
    For Each ActiveReport In Application.CurrentProject.AllReports
        With ActiveReport
            If .IsLoaded Then
                Set Active = Screen.ActiveReport
                With Active
                    DoCmd.SelectObject acReport, ActiveReport.Name
                    DoCmd.MoveSize 0, 1200 'Move window down 1200 twisps
                    Position = Active.WindowLeft
                    DoCmd.MoveSize Position + 1000
                End With
            End If 'Loaded
        End With 'Active Report
    Next ActiveReport

    • Marked as answer by Big Itch Saturday, September 14, 2019 3:35 PM
    Friday, September 13, 2019 6:03 PM
  • Hi Big

    You go this way too.

    File / Options / Current database. The "tabbed documents" setting.


    Cheers // Peter Forss Stockholm


    • Edited by ForssPeterNova Friday, September 13, 2019 6:16 PM
    • Marked as answer by Big Itch Saturday, September 14, 2019 3:36 PM
    Friday, September 13, 2019 6:13 PM
  • The following is a function which does this for multiple instances of a form.  You could try doing similarly by calling the MoveSize method of the DoCmd object, either in a loop as below, or after the code to open each form if this is done consecutively rather than in a loop:

    Function StackCompanyForms()

        Const conSQL = "SELECT * FROM Companies Order By Company"

        Dim dbs As DAO.Database, rst As DAO.Recordset
        Dim n As Integer

        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset(conSQL)
        
        Do While Not rst.EOF
           n = n + 1
           Set frm = New Form_frmCompanies
           colPopups.Add frm, frm.hwnd & ""
           frm.Caption = rst.Fields("Company")
           frm.Filter = "CompanyID = " & rst.Fields("CompanyID")
           frm.FilterOn = True
           frm.Visible = True
           DoCmd.MoveSize n * 360, n * 360
           rst.MoveNext
        Loop
        
    End Function

    So, if opening the reports are opened consecutively rather than in a loop the code would be along these lines:

        Dim n As Integer
        n = 1
        
        DoCmd.OpenReport "FirstReportName", acViewPreview
        DoCmd.MoveSize n * 360, n * 360
        n = n + 1
        
        DoCmd.OpenReport "SecondReportName", acViewPreview
        DoCmd.MoveSize n * 360, n * 360
        n = n + 1
        
        ' and so on

    Experiment with the value to which n is initialised and the factor (in twips) by which it is incremented to get the best fit.

    Ken Sheridan, Stafford, England

    • Marked as answer by Big Itch Saturday, September 14, 2019 3:36 PM
    Saturday, September 14, 2019 12:14 PM
  • Thank you all for your suggestions . . .I will try each and see what fits my situation the best . . .
    Saturday, September 14, 2019 3:36 PM