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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - lock all the controls on a form in one line of code

Status
Not open for further replies.

maxwell2323

Programmer
Sep 22, 2008
12
US
I have a form with a lot of text boxes on it. When the form is first displayed to the user, I want to make sure he cannot type into any of them until a button is pressed. Can I use just one line of code to make sure all of these are locked? Or do I have to wrie a line of code for each one. I am in Access 2003. Thanks in advance.
 
Not one line, but you can do it for all controls like this. This will lock all con

To lock

Code:
Private Sub Form_Current()

Dim ctrl As Control

For Each ctrl In Me.Controls
  If TypeOf ctrl Is TextBox Then
   ctrl.Locked = True
  End If
Next

End Sub

to unlock
Code:
Private Sub UnlockButton_Click()

Dim ctrl As Control

For Each ctrl In Me.Controls
  If TypeOf ctrl Is TextBox Then
   ctrl.Locked = False
  End If
Next

End Sub


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Have a look at the form properties:

AllowEdits
AllowDeletions
AllowAdditions
 
You can also use the tag property to select certain controls you want in your roundup of controls to disable/enable
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top