unload userform1 doesn't

D

David

I use the following to initialize a userform:
Private Sub UserForm_Initialize()
With Me.TextBox1
..Text = "<store name>"
..SelStart = 0
..SelLength = Len(.Text)
End With
End Sub

Then macro code to accept input:
UserForm1.Caption = "Payee 1"
UserForm1.Show
Payee1 = Application.Proper(UserForm1.TextBox1.Text): If Payee1 = "" Then
Exit Sub
Unload UserForm1

Problem is that on subsequent calls, I'm presented with the last store name
instead of the form reinitializing.

How can I correct this?
 
D

David

David wrote
I use the following to initialize a userform:
Private Sub UserForm_Initialize()
With Me.TextBox1
.Text = "<store name>"
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub

Then macro code to accept input:
UserForm1.Caption = "Payee 1"
UserForm1.Show
Payee1 = Application.Proper(UserForm1.TextBox1.Text): If Payee1 = ""
Then Exit Sub
Unload UserForm1

Problem is that on subsequent calls, I'm presented with the last store
name instead of the form reinitializing.

How can I correct this?

Never mind. Problem sorted by using UserForm_Activate instead.
 
D

David

AlfD < wrote
Me.Hide also works (complementary to Userform1.Show)

Not for this dimwitted user. No matter how or where in the routine I tried
to use it, the textbox was never reinitialized to show the default,
highlighted "<store name>". Instead the textbox always displayed my last
input and I had to delete it or backspace over it to type in a new entry.
 
A

AlfD

Hi!

Hiding the userform is one thing. Changing a textbox is another.

Shouldn't you put in a line to reset the textbox to whatever you wis
to be its default value?

AL
 
D

David

AlfD < wrote
Shouldn't you put in a line to reset the textbox to whatever you wish
to be its default value?

That's what I erroneously thought Userform1_Initialize would do before I
stumbled on putting my default text in Userform1_Activate:

Private Sub UserForm_Activate()
With Me.TextBox1
..Text = "<store name>"
..SelStart = 0
..SelLength = Len(.Text)
End With
End Sub
 
Top