Example Apps for Businesses, Schools & Developers

Version 1.4           Approx 0.8 MB (zipped)                 First Published 23 Oct 2023                 Last Updated 24 Oct 2023


My recent article Extend Access across Multiple Monitors provided code that allows the Access application interface to be extended across two or more monitors.

As previously stated, there are several reasons why extending the Access interface across monitors can be useful. For example:
a)   Display several objects such as forms/reports simultaneously without overlaps.
b)   Display a complete datasheet form which is too wide to fit on a single screen across 2 or more monitors horizontally.
c)   Display a complete datasheet form which is too tall to fit on a single screen across 2 or more monitors vertically.
d)   Simulate how your application will look for users with very large, high resolution monitors.
e)   Test the effects of using automatic form resizing with your applications for users with very large, high resolution monitors.
f)   Plan for Access forms wider than the current limit of 22.75 inches (57.79 cm). Microsoft have announced wider forms will be supported in a forthcoming release.
g)   Display a very large number of items across multiple monitors on the Quick Access Toolbar (QAT).

Normally, users would position each object manually according to need. However at times it may be useful to automate this.

In this article, I will demonstrate how objects such as forms or reports can be automatically positioned on different monitors in an Access application interface which is extended across two or more monitors.

However, achieving this result successfully using code, no matter what arrangement is used for the monitor display, proved trickier than expected



The form used in this example app is similar to that in the original app but with additional functionality.

Main Form
A summary of the current monitor arrangement is shown at the top of the form

Click the Refresh/View Monitor Info button to update the monitor info and display in a form:

Monitor Info form
Click the Open Two Forms button to view 2 forms showing the same data as a modern chart or classic chart side by side on the same screen

Two Forms Same Screen

Now click the Extend ACCESS window button (or use the keyboard shortcut Ctrl + E) and then open the two forms again with the following result:
a)   Form 1 (Modern chart) opens near the top left of Monitor 1
b)   Form 2 (Classic chart) opens near the top left of Monitor 2

For example, here the 2 forms are arranged horizontally with Form1 (primary) on the right as shown below

Display Settings Horiz
In this case, the layout on the two screens will be like this:

        Click the image to open a larger version on a new tab
Forms Horizontal
This should happen no matter which is the primary monitor, nor how the two monitors are arranged

You can test this by clicking View Display Settings then rearranging the monitor positions and/or resetting the primary monitor

Display Settings Vert
In this arrangement, the screen layout will be:

Forms Vertical
If you have more than two monitors, the code uses the primary monitor and the first secondary monitor for placing the two forms.



Code (Main Form):

Private Sub cmdExtend_Click()

      If CurrentProject.AllForms("frmMonitors").IsLoaded Then DoCmd.Close acForm, "frmMonitors"

      'recheck the monitor arrangement and update tblMonitorInfo
     CheckMonitorInfo

      'close Form1/Form2 if currently open
      If CurrentProject.AllForms("Form1").IsLoaded Then DoCmd.Close acForm, "Form1"
      If CurrentProject.AllForms("Form2").IsLoaded Then DoCmd.Close acForm, "Form2"

      'extend Access interface across all screens
      ExtendAccessScreens

      blnExtend = True
      cmdExtend.Enabled = False
      cmdRestore.Enabled = True

      Me.lblOpen.Caption = "Open two forms side by side on the primary or secondary monitor."
      cmdOpen.Caption = "Open Two Forms on Different Screens"

End Sub

'=======================================

Private Sub cmdOpen_Click()

     'example of 2 forms opened in different arrangements on multiple screens depending on the setup

     'If the Access interface covers multiple monitors:
     'Form1 always opens near the top left of monitor 1
     'Form2 always opens near the top left of monitor 2

     'Where the interface is limited to a single monitor, the two forms open alongside each other

     MinimizeNavigationPane

      DoCmd.OpenForm "Form2"
      DoCmd.OpenForm "Form1"

End Sub

'=======================================

Private Sub cmdRestore_Click()

      'recheck the monitor arrangement and update tblMonitorInfo
      CheckMonitorInfo

      'close Form1/Form2 if currently open
      If CurrentProject.AllForms("Form1").IsLoaded Then DoCmd.Close acForm, "Form1"
      If CurrentProject.AllForms("Form2").IsLoaded Then DoCmd.Close acForm, "Form2"

      'restores Access interface to fill one monitor only
     RestoreSingleScreen

      blnExtend = False
      cmdRestore.Enabled = False
      cmdExtend.Enabled = True

      Me.lblOpen.Caption = "Open two forms side by side on the current monitor."
      cmdOpen.Caption = "Open Two Forms on the Same Screen"

End Sub



Code (Form1):

Private Sub Form_Load()

      'P2T = 15 (pixels to twips conversion)

      DoCmd.Restore

      Dim lngLeft As Long, lngTop As Long

      lngTop = 200

      If CountMonitors > 1 And blnExtend Then

            Me.lblHeader.Caption = "Form 1 (Modern Chart) on Monitor " & GetPrimaryMonitorID()

            'place near top left of primary monitor
            Select Case GetPrimaryMonitorPosition

            Case "Left"
                  lngLeft = P2T * GetPrimaryMonitorLeft + 200

            Case "Right"
                 lngLeft = P2T * GetSecondaryMonitorWidth + 200

            Case "Top"
                 lngLeft = P2T * GetPrimaryMonitorLeft + 200

            Case "Bottom"
                  lngLeft = P2T * GetPrimaryMonitorLeft + 200
                  lngTop = P2T * GetSecondaryMonitorHeight + 200

            Case "Center"
                  lngLeft = P2T * GetPrimaryMonitorLeft + 200

            End Select

      Else
            Me.lblHeader.Caption = "Form 1 (Modern Chart)"

            'displayed on 1 monitor near top left
            lngLeft = 200

      End If

      DoCmd.MoveSize lngLeft, lngTop, , Me.WindowHeight - 200

End Sub



Code (Form2):

Private Sub Form_Load()

      'P2T = 15 (pixels to twips conversion)

      DoCmd.Restore

      Dim lngLeft As Long, lngTop As Long

      If CountMonitors > 1 And blnExtend Then

            Me.lblHeader.Caption = "Form 2 (Classic Chart) on Monitor " & GetFirstSecondaryMonitorID()

            'place near top left of secondary monitor

            Select Case GetPrimaryMonitorPosition

            Case "Left"
                  lngLeft = P2T * GetPrimaryMonitorWidth + 200
                  lngTop = 200

            Case "Right"
                  lngLeft = P2T * GetPrimaryMonitorLeft + 200
                  lngTop = 200

            Case "Top"
                  lngLeft = 200
                  lngTop = P2T * GetPrimaryMonitorHeight + 200
            Case "Bottom"
                  lngLeft = 200
                  lngTop = 200

            Case "Center"
                  lngLeft = P2T * GetPrimaryMonitorLeft + 200
                  lngTop = 200

            End Select

      Else
            Me.lblHeader.Caption = "Form 2 (Classic Chart)"

            'displayed on 1 monitor to right of Form1
            lngLeft = Me.Width + 500
            lngTop = 200

      End If

      DoCmd.MoveSize lngLeft, lngTop, Me.Width, Me.WindowHeight - 200

End Sub





Issues

As mentioned above, I originally had some issues in getting code to work reliably in all monitor display layouts.
I am mentioning some of the issues here in case you experience similar problems.

1.   Aligning monitors
      For best results, monitors should be similar sizes and resolutions. They should also be top aligned (in a vertical arrangement) or left aligned in a vertical layout.
      Other arrangements may cause part of a form to be off screen. For example, if the monitors are right aligned in a vertical layout:

Vertical Right Align

Forms Vertical Right Align
      Of course, the form can be shifted horizontally so it is completely shown on screen.

2.   Positioning forms
      My original plan was to center the forms on each monitor.
      However doing so triggered error 2498 as the integer limit (32767) was exceeded for the left value in the DoCmd.MoveSize code line.

Error 2498
      I expect this issue will be fixed soon as the Access team have announced that support for large monitors will be added in the relatively near future.

3.   Reports
      If a report is opened in print preview alongside a form, the print preview ribbon could be confusing to end users.

Form & Report (Preview)
      Report view is probably more suitable for this purpose.



Download

Click to download:   Extend Access Window v1.4     Approx 1.2 MB (zipped)



Feedback

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington           Mendip Data Systems                 Last Updated 24 Oct 2023



Return to Example Databases Page




Return to Top