Solved

Lock all text boxes on a form

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

809 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