Clear All userform fields on Open

djossh

Board Regular
Joined
Jul 27, 2009
Messages
243
Hi, I have userform with various controls and text box.. but everytime I open my userform it will show the last data that i've entered..

I want to have a Blank Fields (All fields) everytime i opened my userform. I dont know if it is better to clear all fields on exit but i prefer clearing fields upon opening it..Thanks..
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Code:
Private Sub Userform_Initialize
 
   Me.Textbox = ""
   Me.OptionButton = 0
 
End Sub

But it doesn't sound like you're actually exiting your userform at all, because unless you've set default values for each of your controls at design-time, they should be blank when you start the form up. Text properties shouldn't be preserved and neither should value properties
 
Upvote 0
Code:
Private Sub Userform_Initialize
 
   Me.Textbox = ""
   Me.OptionButton = 0
 
End Sub

But it doesn't sound like you're actually exiting your userform at all, because unless you've set default values for each of your controls at design-time, they should be blank when you start the form up. Text properties shouldn't be preserved and neither should value properties

Thanks for the reply..Im exiting my userform after i made all the entries.. i know that when i open my userform again it should be blank since i unload it already, but i dont know the reason why it is showing my last entry everytime i open my userform that why i ask for this code.. i really dont know how to write codes i just created my userform using codes from forums like this.. Thanks again..
 
Upvote 0
Thanks for the reply..Im exiting my userform after i made all the entries.. i know that when i open my userform again it should be blank since i unload it already, but i dont know the reason why it is showing my last entry everytime i open my userform that why i ask for this code.. i really dont know how to write codes i just created my userform using codes from forums like this.. Thanks again..

Do you have other codes that maybe interfering ? Are you unloading the userform or just hiding it ?
 
Upvote 0
Do you have other codes that maybe interfering ? Are you unloading the userform or just hiding it ?

Here's my code.. maybe you could check if there is something wrong with this code.. thanks

'this is to open by default my worksheet "Form"

Private Sub Workbook_Open()
Sheets("Form").Select
UserForm1.Show
End Sub

' Here are the other codes under userform..
===============================
Private Sub Workbook_Open()
UserForm1.Show
End Sub
===========================
Private Sub CommandButton1_Click()
Unload UserForm1
End Sub
========================
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use OK Button to Close the Form"
End If
End Sub
===========================
 
Upvote 0
I can't make your problem happen on my machine. The values of the controls remain empty between calls of the form, using your code and a form with one textbox and one commandbutton.

I know this is the last thing you want to hear when some random thing like this starts happening. Make sure you don't have any default text set in the controls themselves, and then try using the code above to clear them in a userform_initialize event. That's the best I can figure.
 
Upvote 0
I can't make your problem happen on my machine. The values of the controls remain empty between calls of the form, using your code and a form with one textbox and one commandbutton.

I know this is the last thing you want to hear when some random thing like this starts happening. Make sure you don't have any default text set in the controls themselves, and then try using the code above to clear them in a userform_initialize event. That's the best I can figure.


Thank You for your reply... God Bless...
 
Upvote 0
Does the userform have an Initialize event or an Activate event?
If so, what is the code?

This is the only code that will initialized when i open my workbook

Private Sub Workbook_Open()
Sheets("Form").Select
UserForm1.Show
End Sub
 
Upvote 0
In the userform's code module is there a routine that begins with
Code:
Private Sub UserForm_Initialize()
or
Code:
Private Sub UserForm_Activate()
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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