Solved

Lock all text boxes on a form

Posted on 2004-04-05
4
320 Views
Last Modified: 2012-06-22
I have a form that has several text boxes on it. I wish to LOCK all the text boxes until a certain condition s met.  Is there a way to LOCK all text fields with having to lock each one by its property screen?

The boxes are all named:   textFields(1)    textFields(2)   textFields(3),     etc....

Thanks

Charlie

0
Comment
Question by:CMHamrick
  • 2
4 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10760189
Private Sub Form_Load()
    'Sets .Locked=True for all TextBoxes on Form1
    Dim ctrlText As TextBox
    For Each ctrlText In Me.Controls
        ctrlText.Locked = True
    Next ctrlText
End Sub
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10760243
'use the KeyPress event.

Private Sub textFields_KeyPress(Index As Integer, KeyAscii As Integer)
If "your condition" = "criteria" Then
    textFields(Index).Locked = True
End If
End Sub

S
0
 

Author Comment

by:CMHamrick
ID: 10760252
That did not work... error on:       ctrlText     ????
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 500 total points
ID: 10760267
What's the error? It loops through the object collection for TextBoxes and sets the Locked=True for each one.

Alternate:

Private Sub Form_Load()
    Dim objTmp As Object
    For Each objTmp In Me.Controls
        If TypeOf objTmp Is TextBox Then
            objTmp.Locked = True
        End If
    Next objTmp
End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question