Form Text Box Fields, global changes

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Thank you in advance for looking at this problem, its driving me
crazy......not to mention !%^#^$%#

I have a form with over 150 text box fields. I would like a function that
goes throught every text box field and sets the locked value to True. I
need to control certain fields out of the 150 based upon who is using the
form.

Note that my field names are not indexed. They have different names like
TankNumber, Diameter, etc..

In my example below I say "accessobject.textbox(i)" I am not sure what to
call this to get at each text box field via an index of some sort. Can
anybody help? This is driving me crazy, I have seen something like this
done but can't find where I seen this.

Example:

Call GetAccessTextBoxObjects ??????

For i = 1 to 150
accessobject.textbox(i).Locked=True
next i

select case t
case "ENGR"
accessobject.textbox(5).Locked=False (or same as) TankNumber.Locked
= True
accessobject.textbox(8).Locked=False (or same as) Diameter.Locked =
True
accessobject.textbox(12).Locked=False (or same as) Height.Locked =
True
case "EHS"
accessobject.textbox(15).Locked=False (or same as) SafetyRoof.Locked
= True
accessobject.textbox(28).Locked=False (or same as)
Registration.Locked = True
accessobject.textbox(61).Locked=False (or same as)
PayRegistration.Locked = True
else else
end select

Thank you in advance for any help,
Mike
 
Hi, Mike.

The simplest approach to this is to loop through the Controls collection,
and utilize the "free" Tag property. Enter a common value in the textboxes
that you'd like to turn off. The code then becomes very simple:

Dim ctl as Control
For Each ctl In Me.Controls
If (ctl.ControlType = acTextBox AND ctl.Tag = YourValue) Then
ctl.Locked = True
End If
Next ctl

Sprinks
 
Sorry, Mike; I didn't handle cases for different people. An easy way to do
that is to use a multiple-digit code in the Tag field, as many digits as
there are personnel types. Let's say the Engineer is assigned the first
digit, and "EHS" is the second digit. In fields you wish to turn off for the
engineer, set the first digit to, say, '1', similarly for EHS in the second
digit:

11 Turn off field for both engineer and EHS
01 Turn off field only for EHS
10 Turn off field only for engineer

Then use your select case statement to assign a variable for the digit to
look at:

Dim intTagChar as Integer
Dim ctl as Control

Select Case t
Case "ENGR"
intTagChar = 1
Case "EHS"
intTagChar = 2
End Select

For Each ctl in Me.Controls
If (ctl.ControlType = acTextbox and Mid(ctl.Tag, intTagChar, 1) = '1'
Then
ctl.Locked = True
End If
Next ctl

Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top