Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default How to clear items on a form?

Hi,

I have a user form with details such as first name and last name. IF the
user wishes to start again, I would like a clear or reset button to clear the
fields that they have typed.

Is there a way to loop through each textbox to clear it to blank?

Thanks

G
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default How to clear items on a form?

G,

Grd wrote:
I have a user form with details such as first name and last name. IF
the user wishes to start again, I would like a clear or reset button
to clear the fields that they have typed.

Is there a way to loop through each textbox to clear it to blank?


Here's one way:

Private Sub ClearAll()
Dim ctl As Control

For Each ctl In Controls
If TypeOf ctl Is MSForms.TextBox Then
ctl.Object.Text = ""
End If
Next ctl
End Sub

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]


  #3   Report Post  
Posted to microsoft.public.excel.programming
dtb dtb is offline
external usenet poster
 
Posts: 3
Default How to clear items on a form?

It's not elegant, but assuming you name all your TextBox controls
consistently (i.e. begin with txt) then the following will work.

Dim ctrl As Control

For Each ctrl In UserForm1.Controls
If Left(ctrl.Name, 3) = "txt" Then
ctrl.Text = ""
End If
Next

Just add this to the Click event of a button on your UserForm.



"Grd" wrote:

Hi,

I have a user form with details such as first name and last name. IF the
user wishes to start again, I would like a clear or reset button to clear the
fields that they have typed.

Is there a way to loop through each textbox to clear it to blank?

Thanks

G

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
order form with multiple items and sizes for items Bernard56 Excel Discussion (Misc queries) 1 January 17th 06 11:43 PM
How to clear a form from the screen GordonNewBie Excel Programming 1 December 13th 04 07:10 PM
2nd Form deselects list box items on main form RandyDtg1 Excel Programming 3 September 5th 04 09:32 PM
Help with a Clear Form Macro DangerMouse114[_3_] Excel Programming 2 May 25th 04 07:25 AM
clear the Form Saj Excel Programming 5 December 1st 03 06:32 PM


All times are GMT +1. The time now is 07:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"