text boxes retaining their last value on form close and restart

N

NDBC

In my user form there are 5 text boxes. Rider1 through Rider5. Is there a way
to store the values of these text boxes so the last values come up as the
starting values if the user accidently closes down the form (x in top right)
and then clicks the button to restart it.

Thanks
 
J

Jacob Skaria

Insert a module and declare variables to store these values which will remain
untl the user close the workbook.

If this post helps click Yes
 
J

Jacob Skaria

If you are new to VBA/programming; from VBAProject Explorer right click the
userform icon. Insert Module and declare your vairables as below

Public strTextBox1 As Variant
Public strTextBox2 As Variant
Public strTextBox3 As Variant

-----------------------------------------------------------------------------
In userform code store the values on terminate and reassign on activate

Private Sub UserForm_Activate()
Rider1.Text = strTextBox1
Rider2.Text = strTextBox2
Rider3.Text = strTextBox3
End Sub

Private Sub UserForm_Terminate()
strTextBox1 = Rider1.Text
strTextBox2 = Rider2.Text
strTextBox3 = Rider3.Text
End Sub

If this post helps click Yes
 
D

Dave Peterson

It sounds like you've assigned a cell to the ControlSource property for the
textboxes.

You may find it easier to drop that technique and use the OK button to update
the cells with the values from the textboxes.

And you can use the _initialize procedure to populate the textboxes with the
values from the cells:

Option Explicit
Private Sub UserForm_Initialize()
Me.TextBox1.Value = Worksheets("Sheet1").Range("A1").Text
End Sub
 

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