mass enable and locked controls

icemonster

Registered User.
Local time
Today, 06:22
Joined
Jan 30, 2010
Messages
502
what's the best way to mass enabled and lock controls?

e.g

i have 20 fields that i want to enabled altogether in 1 command and lock it altogether? any thoughts?
 
Again, depending on naming conventions it will determine the best way to do it.

If you have controls named Txt01, Txt02, Txt03, Etc you could use a loop. Other than that you could put all the code in a sub routine and then call the sub routine


Code:
Private Sub Enable(eFlag As Boolean)

Me.Txt1.Enabled = eFlag
Me.Txt1.Locked = Not eFlag

repeat for other controls

End Sub

Then when you want to use the sub simply use Call Enable(False/True) to enable/disable the required controls. This also set the Locked property to the opposite of the Enabled property to work in tandem with it.
 
Last edited:
it may seem a bit of a pain - but you only have to set it all up once, if you do it in the way DC just suggested
 
or else you can put the word Lock in the tag of any text box you want to control and use this (put it in a standard module and name the module something other than this function name) :
Code:
Function LockUnlock(FormName As String, TagToUse As String, LockUnlock As Boolean)
Dim ctl As Control
 
For Each ctl In Forms(FormName).Controls
   If ctl.Tag = "Lock"
      ctl.Locked = LockUnlock
   End If
Next
End Function

And then you can call it for any form

to lock:
LockUnlock Me.Name, "Lock", True

to unlock:
LockUnlock Me.Name, "Lock", False
 

Users who are viewing this thread

Back
Top Bottom