Fix a VBA Control Loop on a Microsoft Access Tabbed Subform
Question details
The user needs to hide or show controls on a tabbed Access subform using a VBA loop.

- 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.
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.
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.
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.
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.
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
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.
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.

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.

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.




