Page 1 Page 2

Version 3.75                     Last Updated 2 Apr 2022                        Difficulty level:     Moderate

Section Links (this page):        How Does the Code Work?        Zoom Form         Datasheets        Other Code        Downloads


In the first part of this article, I discussed the benefits of automatic form resizing as well as an alternative approach based on layout guides and anchoring.

In the second section, I showed how the resizing code can add an adjustable zoom feature in your forms. It also covered some potential issues together with possible solutions for each of these.

The final part of this article explains how the code works and provides tips for using the code most effectively in your own applications.



1.   How Does the Code Work?                                                   Return To Top

All the code used in the automatic form resizing process is contained in the module modResizeForm.
The code works in both 32-bit and 64-bit versions of Access

No additional VBA references are required

There are a number of procedures used of which the following are the most important.

First of all, the declarations section of the module modResizeForm includes the following lines:

AFR14

The first line is the default or baseline horizontal resolution - in this case 800
You can adjust this to any other suitable minimum value such as 1024 or 1280 if you prefer

The next line is the baseline vertical resolution - 600
This can also be amended to suit, but in the current version of the code this is NOT used & can be disabled

The third line is the pixels per inch setting which is normally 96 for 100%
NOTE: if the screen scaling is magnified to e.g. 125% this value becomes 120 ppi. The code still works perfectly.

Based on this information, the GetFactor function calculates the multiplying factor based on screen size & resolution:

AFR50

HINT:
If all the screens on which your application will be displayed are known to have the same form factor e.g. widescreen, you should set your default form size/shape accordingly to match that.

The Resize procedure then uses the GetFactor value to adjust the height and width of the form together with the size and position of each control on the form.

AFR51

The Resize procedure gives 'special treatment' to selected controls – list boxes, combo boxes and tab controls - to manage their individual features.

Tab control pages are excluded as are the contents of subforms (the subform container is resized automatically)

As previously stated, the code line ResizeForm Me needs to be added to the Form_Load event of each form being resized.
This code line means the ResizeForm procedure is applied to the loaded form (Me)

To scale up the subform control positions / sizes, add the line ResizeForm Me to the Form_Load event of the subform.
Alternatively, add a line like ReSizeForm subFormName.Form to the Form_Load event of the main form.

NOTE: DO NOT DO BOTH METHODS or the subform will be scaled up twice!!

AFR52

The code first checks whether resizing is required then uses the Resize procedure above

Following that two adjustments may be made:
a) For popup forms an adjustment is made to the code to fix possible positioning issues. However this can be disabled if necessary by setting the form Tag value = 1
b) Where the display option is set to tabbed documents (UseMDIMode=0), the navigation pane is first maximised and then minimised again.
    This again fixes positioning issues.

HINT:
If you have a form that is sometimes used as a subform, you can conditionally apply resizing code when used as a standalone form.
To do so, place the following IsSubform code in the subform itself:

AFR53

The UnResizeForm procedure can be used to fix issues when forms become 'over-enlarged'.
This reverses the form resizing code and effectively 'shrinks' the form again.

AFR54

This code is used in both the frmFormUnresizer form and the FixFormSize procedure:

AFR55

Very occasionally, you may experience a form that does not automatically revert to its correct size on closing.
In such cases, try adding the line UnresizeForm Me in the Form_Close event.
I also do this where conditional resizing code is applied to subforms (as above)




2.   Zoom Form Code                                                                           Return To Top

The new ZoomForm procedure is a modified version of the original ResizeForm code.

AFR56

Additional code is used in the form being zoomed.
First of all the form is 'unresized' then resized by an additional amount based on the sngZoom multiplier
Adjustments are made to the form width and section heights to ensure the form dimensions remain in proportion.
This is done by comparing with the sizes of four hidden lines placed on each section of the form

AFR57



3.   Datasheet Code                                                                           Return To Top

Standard resizing code does not work for datasheets. Instead the code first multiplies the font height by the GetFactor function value.
Next the code loops through each column and adjusts the widths of each automatically.
NOTE: This causes error 438 which is handled automatically by the code

AFR58

The datasheet zoom code is very similar. Firstly the font height is further adjusted up/down by the zoom factor
Next the code loops through each column and adjusts the widths of each automatically.
This again causes error 438 which is handled automatically by the code

AFR59



4.   Other Code                                                                                     Return To Top

Several other procedures are also included in modResizeForm:

a)    GetScreenResolution / GetResolution / GetHorizontalResolution / GetVerticalResolution / GetScreenShape
b)    GetTopOffset / GetLeftOffset - used to centre forms on screen
c)    AdjustColumnWidths - used in Resize procedure to adjust combo boxes & list boxes during resizing
d)    GetOrigWindow - used to note the original form dimensions before resizing
e)    RestoreWindow - can be used in the Form_Close event to restore the original form dimensions



5.   Downloads / Review                                                             Return To Top

Click the links to download various items related to this topic:

1.   The original auto form resize utility by Jamie Czernik - afr2003jc.zip (MDB zipped)

2.   The example application referenced in this article - ResizeFormExample_v3.75.zip (ACCDB file zipped)

3.   The complete article as a PDF document - ResizeForm Me.pdf (PDF zipped)

4.   I ran a session on Automatic Form Resizing for the US Lunchtime Access User Group on 28 Sept 2021.
      The video is available on You Tube at: https://youtu.be/-mgIvCosYtU or you can click on the video below.

       

      Many thanks to Crystal Long (MVP) for the considerable time she spent expertly editing the video recording of this session.

      More recently, I have done updated versions of the same presentation for the UK Access User Group on 8 Feb 2022 and again for the Denver Area Access
      User Group on 17 Feb 2022. The updated presentation also included the use of AFR with datasheet forms and navigation forms

      The video of the Denver Area AUG session is now available on You Tube at: https://youtu.be/dzk9rM5A9zU

I would be grateful for any feedback on this article including details of any errors or omissions
If you have any comments or questions, please contact me using the feedback form below or by email

Colin Riddington      Mendip Data Systems        Last Updated 2 Apr 2022


Click any image to view a larger version

Click any image to view a larger version

Return to Access Articles
Page 3 of 3
1 2 3 Return To Top Return to Home Page

Click any image to view a larger version

Click any image to view a larger version