How do I clear the Excel VBA controls on my user form in one hit ?

Hi Experts,

I have a user form with a number of controls including buttons.
One of the buttons is a CLEAR button which will clear each of the text boxes of any data. It currently does this as follows:

   coClientName = ""
   teClientAddress1 = ""
   teClientAddress2 = ""
   teClientAddress3 = ""
   teClientTown = ""
   teClientPostcode = ""

....and so on for the whole form.

My question is : how can I do this for the whole form in one line of code, rather than clear each control individually ?

Thanks
Toco
TocogroupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveCommented:
I do not belive that you can use a single line to clear all controls.
This would be because not all controls can be cleared.
The best I can think of is to clear all of a type by cycling all controls on the form.
This way you don't have to write the clear code for each control:

Dim ctl As Control
For Each ctl In Me.Controls
    If TypeName(ctl) = "ComboBox" Or TypeName(ctl) = "TextBox" Then
        ctl.Value = ""
    End If
Next ctl

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TocogroupAuthor Commented:
Thanks Barman, that's saved me a lot of unnecessary code.

Much obliged
Toco
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.