Solved

Controling all text boxes

Posted on 2001-08-14
12
156 Views
Last Modified: 2010-05-02
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
Comment
Question by:dhamijap
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6385348
i guess this is better:

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

Cheers
0
 
LVL 3

Accepted Solution

by:
Diveblue earned 20 total points
ID: 6385350
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
 
LVL 3

Expert Comment

by:Diveblue
ID: 6385355
angel's version is good too
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:hes
ID: 6385364
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
 
LVL 14

Expert Comment

by:wsh2
ID: 6385383
<---- 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
 

Author Comment

by:dhamijap
ID: 6385391
angelIII
I tried yours it did not work. it went through the loop though.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6385394
ooops, too late :-)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6385404
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
 

Author Comment

by:dhamijap
ID: 6385428
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
 

Author Comment

by:dhamijap
ID: 6385436
Very good. Thanks a lot.
0
 
LVL 20

Expert Comment

by:hes
ID: 6385471
dhamijap,
No need to be sorry, we work as a team here. Glad you got yor solution so quick.
0
 

Author Comment

by:dhamijap
ID: 6385514
Like your thoughts. Thanks a lot
dhamijap
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 83
Advice in Xamarin 21 109
Formula problem with Excel attachment 6 43
adding "ungroup sheets" to existing vbs code 5 56
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question