Last active
June 2, 2016 06:42
-
-
Save Phuseos/c1baf4db92598a4f977c62e930523ef8 to your computer and use it in GitHub Desktop.
Lock controls on Main and Subforms (Access / VBA)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub LockSubFormControl() | |
'if called, locks all controls present on main and subform | |
'where frmMain is the currently active main form | |
'and frmSubForm the subform, located inside the main form | |
For Each ctl in Forms!frmMain.Controls 'Loop through the controls | |
Select Case ctl.ControlType | |
Case acTextBox, acComboBox, acCheckBox, acCommandButton 'Select the most used controls to lock | |
ctl.Enabled = False 'Lock the controls | |
Case Else 'Lock everything else | |
ctl.Enabled = False | |
End Select | |
Next 'Keep the loop going until all controls have been locked | |
For Each ctl in Forms!frmMain!frmSubForm.Controls 'Target the subform | |
Select Case ctl.ControlType 'Select the controls to lock | |
Case acTextBox 'Textboxes | |
ctl.Enabled = False | |
Case acComboBox 'ComboBoxes / DropDownLists | |
ctl.Enabled = False | |
Case acCheckBox 'CheckBoxes | |
ctl.Enabled = False | |
Case acCommandButton 'Buttons | |
ctl.Enabled = False | |
Case Else 'Rest | |
ctl.Enabled = False | |
End Select | |
Next | |
end sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment