Set all textbox controls of a form to 'edit false'

  • Thread starter Thread starter Gina
  • Start date Start date
G

Gina

Hi all.

again I would need your help to solve another problem ....

What I would like to do is to set all the controls of a form and subform to
be 'non editable' if it's a textbox or cbobox
I have setup 3 user levels and the at level 0 no edits should be allowed
so I want it to to take place via code ....

I would be very grateful for your help
Thanks

Gina
 
Gina said:
What I would like to do is to set all the controls of a form and subform to
be 'non editable' if it's a textbox or cbobox
I have setup 3 user levels and the at level 0 no edits should be allowed
so I want it to to take place via code ....

First create a procedure to set the Locked property on all
the text and combo boxes on a form:

Private Sub SetLocks(frm As Form, OnOff As Booloean)
Dim ctl As Control

For Each ctl In frm
If ctl.ControlType = acTextbox _
Or ctl.ControlType = acCombobox Then
ctl.Locked = OnOff
End If
Next ctl
End Sub

Then you can call the procedure in your user level checking
code:

Select Case userlevel
Case 0
SetLocks(Me, True)
SetLocks(Me.subformcontrol.Form, True)
Case 3
SetLocks(Me, False)
SetLocks(Me.subformcontrol.Form, False)
. . .
End Select
 
Thanks Marshall .....!!!

I was playing around with that textbox control type but I didn't think of
acTextBox ...

You code works great and straight away !! but one thing has happened which
isn't so good :-((

now users at level 0 cannot choose names from the cboboxes
according to the name (or custID) the rest in the linked subform(s) is
displayed ...

what I wanted is to have is the whole thing just read-only at userLevel 0
but with the locked property on the cboBoxes they cannot do anything with it
anymore ...

well, what else could I use instead of the locked property ??

Gina
 
It's the Locked property with or without the Enabled
property, dependin on if you care if the users can click in
the controls. Either way they won't be able to change the
values.

What you need is something more discriminating than just the
control type. The Tag property is convient for this kind of
thing so let's set the Tag property of the controls you want
to lock to LOCK and leave it blank for all the other
controls. Then the If statement would look like:

If ctl.Tag = "LOCK" Then

The rest of the code would be the same.
 
Thanks Marshall,

this sounds great ....
this way I could do the checking in one nice function !!!

I never knew, what this TAG means

Gina

Marshall Barton said:
It's the Locked property with or without the Enabled
property, dependin on if you care if the users can click in
the controls. Either way they won't be able to change the
values.

What you need is something more discriminating than just the
control type. The Tag property is convient for this kind of
thing so let's set the Tag property of the controls you want
to lock to LOCK and leave it blank for all the other
controls. Then the If statement would look like:

If ctl.Tag = "LOCK" Then

The rest of the code would be the same.
--
Marsh
MVP [MS Access]

You code works great and straight away !! but one thing has happened which
isn't so good :-((

now users at level 0 cannot choose names from the cboboxes
according to the name (or custID) the rest in the linked subform(s) is
displayed ...

what I wanted is to have is the whole thing just read-only at userLevel 0
but with the locked property on the cboBoxes they cannot do anything with it
anymore ...

well, what else could I use instead of the locked property ??

subform
to
 
Back
Top