increment through controls on form

B

BW

I have a form that I've name the controls on it in such a way that I could
determine through open args if it should be locked or not. Example any text
box that begins with txtd would be unlocked with open args of 1. I was
hoping there was a way I could just move through the controls in a loop and
set that property with one function.....I'm not for sure how to accomplish
this though. Does anyone have some sample code on how to "loop" through all
the controls on a form and set the locked property? I can write the
criteria portion if I could get a sample of how to setup the for each
statement.


Thanks
BW
 
B

Beetle

Something like this might work;

Dim ctl As Control

For Each ctl in Me.Controls
If Left(ctl.Name,4) = "txtd" Then
ctl.Locked = True
Else
ctl.Locked = False
End If
Next ctl
 
J

John W. Vinson

I have a form that I've name the controls on it in such a way that I could
determine through open args if it should be locked or not. Example any text
box that begins with txtd would be unlocked with open args of 1. I was
hoping there was a way I could just move through the controls in a loop and
set that property with one function.....I'm not for sure how to accomplish
this though. Does anyone have some sample code on how to "loop" through all
the controls on a form and set the locked property? I can write the
criteria portion if I could get a sample of how to setup the for each
statement.


Thanks
BW

The Tag property of controls may be handy here. You could have a value in the
tag which indicates that it should be locked, or locked based on the value of
OpenArgs.

in either case, looping through the Controls collection is easy:

Dim ctl as Control
For Each ctl In Me.Controls
<do something with the control, e.g. check if you want to lock it>
If <you want to lock it> Then
ctl.Locked = True
End If
Next ctl

Just note that this loops through ALL the controls - labels, lines,
rectangles, textboxes, etc. - not just databearing controls.
 
B

BW

Worked Great....Thanks


BW
John W. Vinson said:
The Tag property of controls may be handy here. You could have a value in
the
tag which indicates that it should be locked, or locked based on the value
of
OpenArgs.

in either case, looping through the Controls collection is easy:

Dim ctl as Control
For Each ctl In Me.Controls
<do something with the control, e.g. check if you want to lock it>
If <you want to lock it> Then
ctl.Locked = True
End If
Next ctl

Just note that this loops through ALL the controls - labels, lines,
rectangles, textboxes, etc. - not just databearing controls.
 

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

Top