How to Vertically Center Form and Subform Controls in Access with VBA
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.

- 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.
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.
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.
Open your database, right-click the main form, select 'Design View', and press Alt + F11 to open the Microsoft Visual Basic for Applications editor.
Write a 'For Each ctrl In Me.Controls' loop to iterate through the controls on the main form.
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.
Call a similar loop procedure referencing the subform's specific control collection (e.g., 'Me.YourSubformControlName.Form.Controls') to adjust its nested elements.

Apply Built-in Stacked or Tabular Layouts
Use Microsoft Access's built-in layout manager to easily align and distribute controls without writing VBA code.
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. Download the Installer: Visit the official WPS website and click the free download button for your operating system.
- 2. Install WPS Office: Run the downloaded installer and follow the on-screen instructions to complete the quick setup.
- 3. Open and Edit Files: Launch WPS Office and instantly open your existing DOCX, XLSX, or PPTX files with zero formatting loss.

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.




