Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you lock all form controls? 1

Status
Not open for further replies.

Mike555

Technical User
Feb 21, 2003
1,200
0
0
US
When users log into my application, their UserName is stored in a public variable named strUser. I'm trying to program a form's OnOpen event to check if strUser = "JaneDoe" and, if it does, I need to lock all controls on the form. I can't seem to figure out how to lock all controls.

I've tried setting the .AllowEdits and .AllowAdditions properties to false, thinking this would be essentially the same as locking all controls, but these properties actually cause all form controls to be hidden.
Code:
Private Sub Form_Open(Cancel As Integer)
If struser = "JaneDoe" Then
Me.AllowEdits = False
Me.AllowAdditions = False
End If
End Sub

How can I lock all form controls? Thanks.

--
Regards,
Mike
 
How about something like this(which will disable controls on your form):
Code:
Dim ctl As Control

For Each ctl In Me.Controls
    If Not TypeOf ctl Is Label Then
        ctl.Enabled = False
    End If
Next ctl
It only checks that it is not a label (as they don't support the .enabled property but it can be easily modified.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
I don't have the syntax for looping through each control on the form off the top of my head, but basically you want to go through and set the properties for each textbox, combobox and listbox.

Me!controlname.locked = True
Me!controlname.enabled = false


Maq [americanflag]
<insert witty signature here>
 
Thanks! Worked Perfectly!

--
Regards,
Mike
 
Although "interesting" in concept, these will generally be unsuitable. What IS hte lady to do when ALL of the controls are lodcked? Can't enter / edit anything, so the only thing left is to re-size or exit via the form's "X" box at the upper right?



MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top