Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing text boxes

Status
Not open for further replies.

Omono

MIS
Apr 20, 2001
24
0
0
US
I have multiple forms into which users enter numbers to calculate. I want to put a reset button on the form. Once they have calculated and wish to try different numbers, they select the reset button which clears all text boxes and returns them to the first box to enter new data. Any help is appreciated.
Thanks,
O'Neal
 
Dim Ctl as Control

For Each Ctl in Form1
If Ctl is TextBox Then
Ctl = ""
End IF
Next Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
If you know all of the textboxes then you can do something like the following:

Sub cmdReset_Click

txtBoxOne.Text = ""
txtBoxTwo.Text = ""
txtBoxThree.Text = ""
...
txtBoxLast.Text = ""

txtBoxOne.SetFocus

End Sub

If you can't enumerate all of the textboxes, you can loop thru the controls collection

Sub cmdReset_Click

Dim cntl as Control

For Each ctl0 In Me.Controls
If TypeOf cntl Is TextBox Then
cntl.text = ""
End If
Next

End Sub

In this second example, the choice of which textbox to set the focus too is not too clear. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Craig and Cajun,

What was with the long post on the constant vbNullString all about? Ofreeman, instead of setting your textbox = "" set it = vbNullString as it is much faster. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
lol - some habits are hard to break - thanks foada Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Thanks to all of you now everything works the way I had envisioned it. I had neglected to set the focus.
ONeal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top