Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

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
0
dhamijap
Asked:
dhamijap
  • 4
  • 3
  • 2
  • +2
1 Solution
 
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:
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
 
DiveblueCommented:
angel's version is good too
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now