Full Version: loop through controls on sub form to disable command buttons
UtterAccess Forums > Microsoft® Access > Access Forms
I am trying to code some security into my database. I want to add a SELECT CASE statement on the opening event of my main form. But I need to create a loop that will run through each tab and disable any command buttons.
nother question what is the proper way to refer to a subform on a tab control from the main form?
A tab control has no effect on the syntax for fields on forms or subforms.
o refer to a control on a subform you need:
Note that:
NameOfSubformCONTROLonMainForm is not necessarily the same as the name of the subform that is contained in that subform control. (Just as the name of a textbox is not necessarily the same as the name of the field it contains).
Even though a control is contained within a tab control, it is still part of the form itself. Just ignore
the fact that it is contained within a tab control. It is just another control on the form. So:
Me.subformControlName gets you access to the subform control.
I know there is also a way to loop through a form looking for specific control types ie command buttons. Could someone assist me with the syntax?
Larry Larsen
Loop through your form controls and look for acCommandButton and if found Enabled = False
Private Sub Form_Load()
Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acCommandButton Then
            Me(ctl.Name).Enabled = False
        End If
End Sub

This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.