locating and changing multiple controls on a page

T

TB

Hi All:

How do I find all textboxes on a page and change a certain property
('enabled' for example) on each of them?

I thought of doing something like this:
sub changemytexboxes()
Dim mytxb As TextBox
For Each mytxb In Me.Controls
ctrlname.Enabled = False
Next
End sub

But when I do that, I get a casting error.

Or do I have to use findcontrol? If so, how?

Any advice would be highly appreciated.

Thanks

TB
 
E

Erik Funkenbusch

I thought of doing something like this:
sub changemytexboxes()
Dim mytxb As TextBox
Dim myctrl As Control
For Each mytxb In Me.Controls
For Each myctrl in Me.Controls
If TypeOf myctrl Is TextBox then
CType(myctrl, TextBox).Enabled = False
End If
Next
ctrlname.Enabled = False
Next
End sub

But when I do that, I get a casting error.

Yes, because the objects are stored as Controls, even though they may be
TextBoxes, also there may be controls on the page that are not TextBoxes,
so that would not be what you were looking for.
 
T

TB

Steve,

It worked perfectly!. Thanks a lot. I changed "Page.Controls" to
'Me.Controls' so that the code would run inside a usercontrol on that
page. I hope that was the correct thing to do.

BTW, you got a very interesting web site.

TB
 

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

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top