Lock userform for editing

T

Tendresse

Is there a way to SHOW a userform as Read Only?
When the userform is initialized, its textboxes and checkboxes are already
populated with data from a worksheet. I don't want the users to change or
edit this data. I only want them to view it. Is it possible to lock the form
for editing?
excel 2003
tendresse
 
P

Per Jessen

Hi

You have to set the Enabled Property to False.

With the code below only CommandButton1 will be active on the form.

Private Sub UserForm_Initialize()
For Each fi In Me.Controls
If fi.Name <> "CommandButton1" Then
fi.Enabled = False
End If
Next
End Sub

Hopes this helps.
 
P

Peter T

As Per suggests the normal way is to set the enabled property to false. This
leaves them greyed, which conforms to conventions to indicate user cannot
change the control. If you do not want the greyed effect you can immediately
exit controls, eg

Put at least two Commandbuttons on a form, a Textbox and a Checkbox. Run the
form and try and change the textbox & checkbox

'userform code
Private mbExitFocus As Boolean

Private Sub CheckBox1_Enter()
If mbExitFocus Then Me.CommandButton1.SetFocus
End Sub

Private Sub TextBox1_Enter()
If mbExitFocus Then Me.CommandButton1.SetFocus
End Sub

Private Sub UserForm_Initialize()
mbExitFocus = True
CommandButton1.Left = -100 ' hide it
End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top