-
Locking Form Controls
Hi again
I have a multi page userform with a variety of controls. Briefly, users complete certain fields, option buttons etc and data is transferred to a hidden sheet. Users can recall this data but cannot make any further amendments. To ensure they cannot amend any data I'm using this code, which works fine:
Code:
For Each ctl In frmMain.Controls
If Not TypeOf ctl Is MSForms.MultiPage Then
If Not ctl.Name Like "*Close*" Then
ctl.Object.Enabled = False
End If
End If
Next ctl
This ensures that several 'Close' command buttons are available to close the form.
However, disabling the controls makes the data slightly difficult to read. Is there a way to loop through and Lock the controls, rather than disable them? Would I need to loop through each control type - combobox, textbox optionbutton etc?
Thanks for any assistance or suggestions.
-
Why does disbaling them make it difficult to read?
What do YOU men by lock?
-
Would it work to set the control's .Visible property?
-
Apologies if I was not clear.
When the controls are disabled Excel makes the font fainter than it was. By locking, I mean that the control will look as normal but the user will not be able to amend the value, for example, when the form is loaded, I format the date field and then lock it, so that users cannot change it
Code:
.txbDate.Value = Format(Date, "dd mmmm yyyy")
.txbDate.Locked = True
The controls need to be visible.
-
You could use a Boolean variable that is module scope, and set that to indicate disabled, and then check it in the controls event. Something like this air code
[vba]
Private fDisabled As Boolean
Private Sub cmClose1_Click()
If Not fDisabled Then
'do your stuff
End If
End SUb
[/vba]
You will have to determine where the Boolean gets set to True and reset back.
-
I understand what you mean, but I don't want the fields disabled, I would prefer them to be locked. This means they would still retain the 'look' of an unlocked field, but users would not be able to amend any data.
-
They wouldn't be disabled, you just cripple the event action.
-