I have a userform containing option buttons, check boxes, list boxes and command buttons all within a frame. What I would like to do is prevent the user from accidentally selecting something while code is being run. As an example to execute code by selecting a command button which processes code based on a selection of option buttons, check boxes and list boxes.
Is it possible to lock the objects all in one sweep after the command button is clicked or is there a better solution?
Userform Lock Objects
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Userform Lock Objects
Regards,
John
John
-
- Administrator
- Posts: 78541
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Userform Lock Objects
For example:
Code: Select all
Private Sub CommandButton1_Click()
Dim ctl As Control
Dim i As Long
On Error Resume Next
For Each ctl In Me.Controls
ctl.Enabled = False
Next ctl
On Error GoTo 0
' Your code goes here
' ...
On Error Resume Next
For Each ctl In Me.Controls
ctl.Enabled = True
Next ctl
On Error GoTo 0
End Sub
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California