Solved

Lock all text boxes on a form

Posted on 2004-04-05
4
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month5 days, 7 hours left to enroll

627 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