| First Published 26 July 2026 | Difficulty level : Moderate |
|---|
The first article in this series showed how forms could be docked to any specified position on the Access window using a selection in a combo box or option group.
The code worked correctly for a wide variety of situations using both standard and popup forms:
• Access window maximised or only occupying part of the screen
• Ribbon maximised/minimised/hidden
• Navigation Pane maximised/minimised/hidden
• Full-screen Mode
• different values for the application default zoom level
However, an important issue is that the original code didn't take into account any changes to zooming after the form has opened.
This is because the Access interface and form window dimensions were not re-calculated after the form has loaded.
This article provides modified code that overcomes this issue. The module code remains unchanged.
However, the form code has been updated to re-calculate the dimensions whenever the zoom level (or the Access window size) is changed. For example:
Standard Form - Docked with Zoom = 140%
Popup Form - Docked with Zoom = 120%
Video
Coming soon
Changes to Form Code
The updated code now includes several form level variables:
Option Compare DatabaseOption ExplicitDim sngZoom As Single, sngOldZoom As SingleDim lngWidth As Long, lngHeight As LongDim blnDrag As Boolean
The Form_Load event now has two additional code lines to get the original width and height of the form and save it as variables lngWidth and lngHeight.
Private SubForm_Load()DimfwAs NewclFormWindowfw.hWnd=Me.hWndWithfw'Get original size (v2.2)lngWidth= .WidthlngHeight= .Height'move to center.Top= (.Parent.Height- .Height) / 2.Left= (.Parent.Width- .Width) / 2End WithSetfw=Nothing'get captions for labels in form footerGetFormFooterCaptionsMeMe.txtZoom=Me.Properties("Zoom")End Sub
The code used to drag the form has two extra lines. These clear the option group (or combo box) position value and set the blnDrag variable to True:
Private SubcmdDragForm_MouseDown(ButtonAs Integer,ShiftAs Integer,XAs Single,YAs Single)'drag form to new positionX=ReleaseCapture()X=SendMessage(Me.hWnd,WM_NCLBUTTONDOWN,HT_CAPTION, 0)'clear the option group setting & set boolean variable trueMe.fraPosition= 0'v2.2blnDrag=True'v2.2End Sub
The option group (or combo box) AfterUpdate event resets blnDrag to False, indicating that the position has been reset:
Private SubfraPosition_AfterUpdate()DimfwAs NewclFormWindowblnDrag=False'v2.2fw.hWnd=Me.hWndWithfwSelect Case Me.fraPositionCase1'Top Left.Top= 0.Left= 0Case2'Centre Left' Access window - form - Access window scrollbar.Top= (.Parent.Height- .Height) / 2.Left= 0Case3'Bottom Left' Access window - form - Access window scrollbar.Top= .Parent.Height- .Height- 1440 / 255.Left= 0Case4'Top Centre' Access window - form - Access window scrollbar.Top= 0.Left= (.Parent.Width- .Width) / 2Case5'Centred.Top= (.Parent.Height- .Height) / 2.Left= (.Parent.Width- .Width) / 2Case6'Bottom Centre' Access window - form - Access window scrollbar.Top= .Parent.Height- .Height- 1440 / 255.Left= (.Parent.Width- .Width) / 2Case7'Top Right' Access window - form - Access window scrollbar.Top= 0.Left= .Parent.Width- .Width- 1440 / 255Case8'Centre right' Access window - form - Access window scrollbar.Top= (.Parent.Height- .Height) / 2.Left= .Parent.Width- .Width- 1440 / 255Case9'Bottom right' Access window - form - Access window scrollbar.Top= .Parent.Height- .Height- 1440 / 255.Left= .Parent.Width- .Width- 1440 / 255End SelectEnd WithSetfw=NothingEnd Sub
A Form_Timer event runs each second (TimerInterval = 1000) and is used to check the current zoom level. When the zoom level changes, the form is resized in proportion to the new zoom value.
In addition, unless the form has been dragged to a new position, the AfterUpdate event runs again and the form is then repositioned correctly.
Private SubForm_Timer()'NEW v2.2DimfwAs NewclFormWindow'check zoomsngZoom=Me.Properties("Zoom") / 100Me.txtZoom=Me.Properties("Zoom")fw.hWnd=Me.hWndIfsngZoom<>sngOldZoomThen'adjust form size if zoom has changedWithfw.Width=sngZoom*lngWidth.Height=sngZoom*lngHeightEnd WithEnd If'update old zoom valuesngOldZoom=sngZoom'recheck positionIf NotblnDragThenfraPosition_AfterUpdateEnd Sub
NOTE:
1. If the form has been manually dragged to a new position (blnDrag = True), the form is resized on zoom change but its relative position is left unaltered.
2. The supplied code will always open popup forms on the primary monitor even if the Access window is on another screen.
3. The code used to reposition forms after zoom changes will only work correctly for one form opened at any time.
Download
Click to download:
DockForms_v2.2 ACCDB file - approx 0.8 MB (zipped) - designed for Access 365 version 2607 or later
NOTE: Zooming of standard forms is only supported in Access 365 from version 2605. For popup forms, version 2607 or later is required
As is the case for all files downloaded from the internet, first unblock the downloaded file, unzip it, then save to a trusted location.
For more details, see my article:
Unblock downloaded files by removing the Mark of the Web
Feedback
Please use the Email button in the contact form below to let me know whether you found this article useful or if you have any questions.
Please also consider making a donation towards the costs of maintaining this website. Thank you
Colin Riddington
Mendip Data Systems
Last Updated 26 July 2026
Return to Access Articles Page
Page 2 of 2
1
2
Return To Top
|
|
|