Solved

Lock all text boxes on a form

Posted on 2004-04-05
4
317 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now