By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 748 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Clear a number of textboxes in one time

P: n/a
Hello,

I have a few textboxes placed on a SSTab control devided over 3 tabs
Is there a way to clear all textboxes in one time in stead of one by one.

Someone told me "Use for each item in.........."
???????????
T.i.a.

regards,

Tino Wintershoven
The Netherlands

p.s.
Merry X-mas
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"T. Wintershoven" <pl*********@grp.com> wrote
Hello,

I have a few textboxes placed on a SSTab control devided over 3 tabs
Is there a way to clear all textboxes in one time in stead of one by one.

Someone told me "Use for each item in.........."
???????????

There is no one command to clear all textboxes. You have to do them
individually. Are your textboxes part of an array? If so, use For/Each
on that array. If not, use For/Each on the Controls collection and text
each item to be sure it is a textbox.

If you are doing that sort of thing in several different places, with
sometimes different textboxes, then it may pay to turn it into a command:

Private Sub ClearText(ParamArray Boxes())
Dim box
For Each box In Boxes
box.Text = ""
Next
End Sub

You can use that like:

ClearText Text1, Text3, Text11, Text15
ClearText Text2, Text4

It will accept any number of controls, just be sure they are Textboxes....

HTH
LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #2

P: n/a
Here is the code ...

-Adheer Pai.

' Form/Module declaration
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

Private Sub cmdClearSSTabTextBoxes_Click()
Dim controlOnForm As Control
For Each controlOnForm In Me.Controls 'For each control on this form
'If the Control is a "TextBox" and its parent hWnd = SSTab hWnd set its
Text = ""
If (TypeName(controlOnForm) = "TextBox") And (SSTab1.hwnd =
GetParent(controlOnForm.hwnd)) Then
controlOnForm.Text = ""
End If
Next
End Sub

"T. Wintershoven" <pl*********@grp.com> wrote in message
news:1071616160.292384@cache1...
Hello,

I have a few textboxes placed on a SSTab control devided over 3 tabs
Is there a way to clear all textboxes in one time in stead of one by one.

Someone told me "Use for each item in.........."
???????????
T.i.a.

regards,

Tino Wintershoven
The Netherlands

p.s.
Merry X-mas

Jul 17 '05 #3

P: n/a
> Here is the code ...

-Adheer Pai.

' Form/Module declaration
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Sub cmdClearSSTabTextBoxes_Click()
Dim controlOnForm As Control
For Each controlOnForm In Me.Controls 'For each control on this form
'If the Control is a "TextBox" and its parent hWnd = SSTab hWnd set its Text = ""
If (TypeName(controlOnForm) = "TextBox") And (SSTab1.hwnd =
GetParent(controlOnForm.hwnd)) Then
controlOnForm.Text = ""
End If
Next
End Sub


I would avoid the API call and do it this way instead...

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

Note that both your code and mine will not clear any TextBoxes embedded in
another container even if that container is located on the SSTab control.

Rick - MVP
Jul 17 '05 #4

P: n/a
Thanks all for your reaction.

Tino

"T. Wintershoven" <pl*********@grp.com> wrote in message
news:1071616160.292384@cache1...
Hello,

I have a few textboxes placed on a SSTab control devided over 3 tabs
Is there a way to clear all textboxes in one time in stead of one by one.

Someone told me "Use for each item in.........."
???????????
T.i.a.

regards,

Tino Wintershoven
The Netherlands

p.s.
Merry X-mas

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.