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

using objects in visual basic

P: 75
Hi all,
i need to clear multiple text box using a single button click how can it be done using objects
Nov 9 '06 #1
Share this Question
Share on Google+
3 Replies


100+
P: 267
Hi all,
i need to clear multiple text box using a single button click how can it be done using objects
hi

try

private sub object_click()
text1.text=vbnullstring
text2.text=vbnullstring
etc

end sub
Nov 9 '06 #2

100+
P: 1,646
Hi all,
i need to clear multiple text box using a single button click how can it be done using objects
A standard way of doing this is as follows:
Expand|Select|Wrap|Line Numbers
  1. Dim ctrl As Control
  2.  
  3. For Each ctrl In Me.Controls
  4.    If TypeName(ctrl) = "TextBox" Then
  5.       ctrl.Text = ""
  6.    End If
  7. Next ctrl
  8.  
Nov 9 '06 #3

Expert 5K+
P: 8,434
A standard way of doing this is as follows: ...
You can make this kind of thing a common routine to be included in your bag of tricks, for use in any program. To make it more generally applicable, you can allow it to target specific controls. One simple way is to place something in their .Tag property for it to recognise.

For example, if you pass your form to this sub, it will only hit those textboxes which have "/CLEARME" somewhere in their tag.
Expand|Select|Wrap|Line Numbers
  1. Public Sub ClearTextBoxes(frm As Form)
  2.   Dim ctrl As Control
  3.   For Each ctrl In frm.Controls
  4.     If TypeName(ctrl) = "TextBox" Then
  5.       If InStr(ctrl.Tag, "/CLEARME") Then
  6.         ctrl.Text = ""
  7.       End If
  8.     End If
  9.   Next ctrl
  10. End Sub
To call it from a button on the form, for instance, you would just say
Expand|Select|Wrap|Line Numbers
  1. ClearTextBoxes Me
Nov 9 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.