Clearing textboxes

dave8

Active Member
Joined
Jul 8, 2007
Messages
275
I have some textboxes on my form. There is a button to clear the textbox fields, e.g,

Controls("txtCity").value = ""
Controls("txtState").value = ""


Here's the problem: When I close the form (Unload userform1) and then bring it back up again, the values are still there. How to clear these fields permanently?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
If you put anything into the Text property of the TextBoxes at design time, in the Properies window, that text will always come back as the default text when the UserForm is loaded... so if that is what you did, then just clear that field in the Properties window for each TextBox. Another possibility is that you have VB code populating the TextBoxes somewhere.
 
Upvote 0
If you have set the ControlSource property, the textbox will automatically display the associated cell's content.
 
Upvote 0
My problem is that I can't seem to clear the textbox property. I don't have it populated any where else in the program. I have a piece of code that looks like this:

Controls("txtCity").text = ""

Does this clear the textbox property on my form? It seems to do it, but when I close the form (Unload userform) and call it back up, the data in the textboxes are still there. What can I do to explicitly clear the form fields?
 
Upvote 0
Okay, I got it. I originally typed values in the textbox property for testing purposes. But I thought I can change the property text values in the code.
 
Upvote 0
Okay, I got it. I originally typed values in the textbox property for testing purposes. But I thought I can change the property text values in the code.
Something to keep in mind... VB code does not have any memory from previous executions. When you close a program down, if you did not store your values somewhere (worksheet cell, text file, etc.), then they are lost. If you do store them, then the first thing your code needs to do is read them back in and assign them wherever they are supposed to go. Again, VB code has no memory of prior executions.
 
Upvote 0

Forum statistics

Threads
1,216,460
Messages
6,130,771
Members
449,589
Latest member
Hana2911

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