Solved

Controling all text boxes

Posted on 2001-08-14
12
155 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
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 142

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 142

Expert Comment

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 54
How does CurrentUser work? 10 36
How to measure sizes and angles in scanned images ? 3 63
Prevent user closing word document opened with VB6 6 73
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

808 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