VBA & Macro Problems

Fix a VBA Control Loop on a Microsoft Access Tabbed Subform

Algirdas JasaitisAlgirdas Jasaitis Nov 20, 2026 869 views

Question details

The user needs to hide or show controls on a tabbed Access subform using a VBA loop.

Fix a VBA Control Loop on a Microsoft Access Tabbed Subform
Product
Microsoft Access
Device & OS
not provided
Scenario
A VBA procedure loops through subform controls to change their visibility based on their Tag values.
Observed behavior
Record counting works, but the loop does not hide or show the controls. An incorrect subform reference or suppressed error may be preventing the loop from working.
Before you start

Open the main form in Design View and check the Name property of the subform control in its Property Sheet. This name can differ from the name of the form displayed inside it.

Solution 1Recommended

Reference the subform control and loop through its controls

Use the subform control's Form property to reach the controls on the form it displays, then change the visibility of controls with a matching Tag.

1
Check the subform control name

In the main form's Design View, select the subform control and open Property Sheet > Other. Note its Name value, and replace SubformControl in the code below with that value.

2
Tag the target controls

Open the form displayed in the subform in Design View. For each control you want to hide or show, select it and set Property Sheet > Other > Tag to HideMe.

3
Add the loop

Open the main form's VBA module and add this procedure, replacing SubformControl with the name you checked: Private Sub SetTaggedControlsVisible(ByVal makeVisible As Boolean) Dim ctl As Access.Control For Each ctl In Me.Controls("SubformControl").Form.Controls If ctl.Tag = "HideMe" Then ctl.Visible = makeVisible End If Next ctl End Sub

4
Call the procedure

From a main-form button's Click event, call SetTaggedControlsVisible False to hide the tagged controls or SetTaggedControlsVisible True to show them. Open the main form in Form View and click the button to test.

5
Expose any errors

Temporarily remove or disable On Error Resume Next in the calling procedure and the loop. Run the button again and use the reported error to identify an invalid reference or other issue.

Reference the subform control and loop through its controls
Check focus before hiding: Access cannot hide a control that currently has focus. Move focus to another suitable control, such as the main-form button, before hiding it.
Free Microsoft Office alternative

Work with Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with documents, spreadsheets, and presentations. Its Microsoft Office format support helps you move everyday files between suites. It does not fix Access subform VBA or replace an Access database.

Use a familiar interface for common Office tasksOpen and edit Microsoft Word, Excel, and PowerPoint file formatsMove everyday Office files between suitesKeep documents, spreadsheets, and presentations alongside your Access workflow
microsoft office alternative - wps office

Frequently Asked Questions

How do I find the subform control name?

Open the main form in Design View, select the subform control, and check Property Sheet > Other > Name. Use that name in the VBA reference, even if the displayed form has a different name.

Why does the loop run without changing any controls?

Check that the reference uses the subform control's Form.Controls collection and that the target controls have the expected Tag value. Temporarily disable On Error Resume Next to reveal errors.

How can I show the tagged controls again?

Call SetTaggedControlsVisible True from an event on the main form. The procedure sets Visible to True for controls whose Tag is HideMe.

Why does Access report an error when I hide a control?

A control cannot be hidden while it has focus. Move focus to another suitable control before setting its Visible property to False.