Retaining Values in Userform when called a second time

G

Guest

I have a userform which I load values into via a combobox as follows below.
I want to load these values the first time the user calls the form up. After
load the form, the user then picks an item from the box and I pass this to a
public variable via the combobox change event. The user is then prompted
away from this form and then brought back later. Now when the user comes
back to this form again, I want to bypass the loading of the combobox but
instead retain the value from the public variable. How do I do this? I am
assuming an If stmt which tests to see if this is the first time the form has
been called or would you use a class module for this?



Private Sub UserForm_Initialize()
Dim pg As Control
Dim sht As Worksheet

With UserForm1.ComboBox1
.AddItem "Black"
.AddItem "Blue"
.AddItem "Red"
.AddItem "Green"
.AddItem "Yellow"
.AddItem "Orange"
.AddItem "White"
End With
End Sub

Private Sub ComboBox1_Change()
cmblistvalue = ComboBox1.Value
UserForm2.Label1.Caption = cmblistvalue
End Sub
 
G

Guest

I would think that using UserForm.Hide instead of Unload UserForm would allow
its immediate use without reinitializing the controls. Check out the Hide
method in VBA help.
 
G

Guest

Yup that did it. THanks

JLGWhiz said:
I would think that using UserForm.Hide instead of Unload UserForm would allow
its immediate use without reinitializing the controls. Check out the Hide
method in VBA help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top