Can a UserForm retain info?

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
611
Office Version
  1. 2016
Platform
  1. Windows
Hello forum friends, I have a fairly complex workbook that has two UserForms activated by Command Buttons where users enter Personal and Financial info respectively. I will use the Personal Info UserForm as an example:

The user clicks the button and the UserForm opens, and at a minimum they enter their first and last name, date of birth and gender in separate fields. When they click the OK button in the form, the data they entered is transferred to the appropriate worksheet(s) and the UserForm is cleared. I am wondering if there is a way to code it so that the UserForm will 'retain' the data that was entered the first time so that if the user launches it again, it is still visible to them.

Of course the same applies to the Financial Info UserForm.

Appreciate any help!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
If you close the Userform using Hide the data is retained as long as the workbook remains opened.
But if you close the Userform by using Unload the data in the userform is cleared.
 
Upvote 0
@My Aswer Is This

My mistake, I should have said "even if the workbook is closed". Basically making it permanent unless typed over by the user. Sorry about that.
 
Upvote 0
@MY Aswer Is This

My mistake, I should have said "even if the workbook is closed". Basically making it permanent unless typed over by the user. Sorry about that.
I do not believe that can be done. Unless all the values in the userform were written to a sheet when userform is closed and then when userform is opened next time those same values are written back into the userform. But that could be tricky telling each control to be set back to previous setting. Which would be beyond my knowledge.
 
Upvote 0
You might be able to use the technique I described in my mini-blog article here to save the data (which you would have to read back in and reload to the UserForm controls next time the workbook and/or UserForm was opened)...

A Method To Store Workbook Settings...
 
Upvote 0
You could use a FileSystemObject (FSO) textstream to write the data out to a text file then read the data into the Userform if the file exists in Environ("Homepath").
FSO is part of Microsoft Scripting Run-time (scrrun.dll)

-w
 
Upvote 0
@Rick Rothstein @wsnyder -Thanks to both of you for your suggestions but they seem way beyond my basic capabilities when it comes to writing code. I really would have no idea where to even begin. I was kinda hoping that there was a simpler solution. Fingers crossed...

Thanks again!
 
Upvote 0
Is the data stored in the workbook(important). It's pretty easy to reload some previous data into your userform while opening.
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

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