ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Lock userform for editing (https://www.excelbanter.com/excel-programming/425451-lock-userform-editing.html)

Tendresse

Lock userform for editing
 
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

Per Jessen

Lock userform for editing
 
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.

---
Per

"Tendresse" skrev i meddelelsen
...
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



Peter T

Lock userform for editing
 
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

"Tendresse" wrote in message
...
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





All times are GMT +1. The time now is 11:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com