logo
search
Others

How to Vertically Center Form and Subform Controls in Access with VBA

Guest WriterGuest Writer Sep 27, 2026 869 views

Question details

The user wants to dynamically apply suitable vertical positioning or padding to all controls simultaneously on both a main form and its subform.

How to Vertically Center Form and Subform Controls in Access Using VBA
Product
Microsoft Access
Device & OS
not provided
Scenario
Designing a complex database user interface where consistent control alignment is required across main forms and subforms.
Observed behavior
Adjusting the TopPadding for a single control via code fails to vertically center the remaining controls on the form and does not affect the subform.
Before you start

Ensure you have a backup of your Access database before running VBA scripts that modify form layouts. Switch your target forms to Design View so that properties can be effectively modified.

Solution 1Recommended

Use a VBA Loop to Apply Top or TopPadding Properties

Iterate through the Controls collection of both the main form and subform to apply vertical positioning dynamically.

By looping through the entire Controls collection, you can automate the adjustment of spatial properties. It is important to exclude control types that do not support Top or TopPadding properties to prevent runtime errors.

1
Open the VBA Editor

Open your database, right-click the main form, select 'Design View', and press Alt + F11 to open the Microsoft Visual Basic for Applications editor.

2
Create the Control Loop

Write a 'For Each ctrl In Me.Controls' loop to iterate through the controls on the main form.

3
Add Error Handling or Type Checks

Inside the loop, use 'TypeOf' checks or an 'On Error Resume Next' statement to bypass subform controls, lines, or specific objects that do not support the Top or TopPadding properties.

4
Adjust Subform Controls

Call a similar loop procedure referencing the subform's specific control collection (e.g., 'Me.YourSubformControlName.Form.Controls') to adjust its nested elements.

Use a VBA Loop to Apply Top or TopPadding Properties
Top vs. TopPadding: Consider whether modifying the 'Top' property (overall position) is more appropriate for your design goal than modifying 'TopPadding' (internal spacing).
Free Microsoft Office alternative

Boost Your Daily Productivity with WPS Office

While Microsoft Access handles your complex database management, WPS Office is the perfect solution for your daily document, spreadsheet, and presentation tasks. It provides a lightweight, highly compatible, and free alternative for managing standard office files.

  1. 1. Download the Installer: Visit the official WPS website and click the free download button for your operating system.
  2. 2. Install WPS Office: Run the downloaded installer and follow the on-screen instructions to complete the quick setup.
  3. 3. Open and Edit Files: Launch WPS Office and instantly open your existing DOCX, XLSX, or PPTX files with zero formatting loss.
Free and lightweight office suite for Windows, Mac, and LinuxFully compatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar, intuitive user interface for seamless migrationBuilt-in PDF editing and conversion tools
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get an error when applying TopPadding to all Access controls?

Not all Microsoft Access controls support the TopPadding property. Objects like subform containers, lines, and certain custom ActiveX controls will throw a runtime error. You must use VBA to check the control type before applying the property.

Can I vertically center text inside a text box in Access?

Microsoft Access does not have a native 'Vertical Align: Middle' property for standard text boxes. However, you can achieve a similar visual effect by adjusting the Top Margin property of the text box to push the text downward.

What is the difference between Top and TopPadding in Access VBA?

The Top property determines the control's physical position relative to the top edge of the form section it resides in. TopPadding, on the other hand, dictates the internal space between the control's top border and its actual text or content.