Command Button to Clear all Fields in Form VBA

davin2929

Board Regular
Joined
Oct 13, 2002
Messages
129
I've done a search and can't find my answer. I'm looking to create a command button on a form (clear all) that when clicked will clear all the fields in the form. I plan to use the on click function in VBA. any help?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
It depends on just how fancy you're trying to be and the nature of the form.

Please explain a bit more about what you're actually trying to do.

For example, is your form based on a table/query? (and are you really wanting to clear the contents of a table/query)

Mike
 
Upvote 0
there are a couple of ways to clear the text boxes on a form,
This is in Visual Basic and im not completely if it will work for the form as i haven't had the chance to use it
textbox1.cls
textbox2.cls
textbox3.cls
etc using all the names of text boxes that you would like to use
or you can do this
textbox1.text = ""
textbox2.text = ""
textbox3.text = ""
etc
 
Upvote 0
Tails

What is cls?

When I try it in either VBA or VB6 I get method or data member not found error.
 
Upvote 0
.cls is a command to actuall clear certain objects, when you use it what have you been trying to clear? just textboxes?
 
Upvote 0
Tails

I just tried using the code as you had posted.

Added a few textboxes to a userform in VBA and VB6.

Created a command button that ran code like yours when clicked.

And when I clicked I got that error method.
 
Upvote 0
yeah that is odd, it recognises the command as it puts the c into a capital letter. So the command is recognisable and should work but oh well
just use textbox1.text = ""
etc
 
Upvote 0
tails

Where are you actually using the Cls?

When I try to use it in VB6 it does capitalize the C but doesn't in Excel VBA.
 
Upvote 0
I tryed it in visual basic 6.0 and i still get that error although it does recgonise the command, (which is strange). If you do get visual basic 6 with office then that may the problem. When i used Cls in school last year we were using version 5.0 and we were using the Cls command quite a lot. I'll do a bit of research and find out why its not working.
 
Upvote 0
CLS?

Wow, brings back memories.
I remember using CLS as a command line argument as 'clear screen' in my early DOS days.

What I meant/hinted at with "fancy" is this.
You can name your text boxes using near identical naming syntax allowing you to iterate though the list (like grouping) and also avoiding the need to explictly name each one. This helps if you add more boxes later.

Mike
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top