Controling all text boxes

I am looking for that loop where I can set the properties of all the controls without listing them for example

For each control in frmMain
   if control.type = textbox then
      control.caption = ""
   end if
Next
dhamijapAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DiveblueConnect With a Mentor Commented:
Youve almost got it..

Dim thisControl As Control
For Each thisControl In Me.Controls
  If TypeOf thisControl Is TextBox Then
     thisControl.Text = ""
  End If
Next

hope it helps



0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
i guess this is better:

For each control in frmMain
  if TypeName(control) = "Textbox" then
     control.text = ""
  end if
Next

Cheers
0
 
DiveblueCommented:
angel's version is good too
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
hesCommented:
If you Name all your Textboxes like TxtWhatever then you can use

For Each Control In Form1
If Control.Name Like "Txt*" Then
   Control.Text = "hi"
End If
Next
0
 
wsh2Commented:
<---- Code Begin ---->

   Dim objControl As Control
   For Each objControl In Me.Controls
      If TypeOf objControl Is TextBox Then
         objControl.Text = "This Is A Test"
      End If
   Next objControl

<---- Code End ---->

0
 
dhamijapAuthor Commented:
angelIII
I tried yours it did not work. it went through the loop though.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
ooops, too late :-)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry, it's an uppercase B in the "Textbox" ...

For each control in frmMain
 if TypeName(control) = "TextBox" then
    control.text = ""
 end if
Next

0
 
dhamijapAuthor Commented:
Diveblue you code worked perfect. Just as i wanted.
I am accepting your answer. Sorry hes and wsh2 the first acceptable answer gets the points. Yours looks like it is going to work. Thanks for your response.
0
 
dhamijapAuthor Commented:
Very good. Thanks a lot.
0
 
hesCommented:
dhamijap,
No need to be sorry, we work as a team here. Glad you got yor solution so quick.
0
 
dhamijapAuthor Commented:
Like your thoughts. Thanks a lot
dhamijap
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.