User Form Remembers Last Data Input

Hi All,

I have a custom user form that autopopulates to a document.  I'd like the userform to remember the last data input selected or inputted into its Combo and Text boxes.  Is this possible?

Example: Userform has Text box for contact.  The user types in "Joe Smith" and clicks OK and it's populated into the document.  The next time the template Userform is opened, "Joe Smith" is already displayed in the Userform Textbox.

Currently, the userform is populating the document properly but it would be great if the userform displayed the last data typed the next time it is run.

TIA!


ghinjerseyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
ghinjersey said:
>>Is this possible?

Yes.  I typically do it by using SaveSetting to write the values to the Registry before I shut down the UserForm,
and GetSetting to retrieve the values from the Registry when I load the UF.

The VBA help file has the complete syntax for those statements.
0
GrahamSkanRetiredCommented:
If you hide the form instead of unloading it, the data will be retained during the lifetime of the host application session.
0
ghinjerseyAuthor Commented:
How can I hide it?
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Patrick MatthewsCommented:
How long do you need to "remember" the values?  Graham's method will successfully retain the values
within a session, but then those values evaporate once the userform unloads.  If you need to retain those
values across multiple sessions, I think the Registry is a pretty good way to go.

But it all comes down to what your needs are.
0
GrahamSkanRetiredCommented:
UserForm1.Hide

You can show it again with

UserForm1.Show vbModal
 or
UserForm1.Show vbModeless
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ghinjerseyAuthor Commented:

I think I just need to hide it because the Word template is being intrgraded with another Program for Mail Merging.

Can I just put this code:

"UserForm1.Hide

You can show it again with

UserForm1.Show vbModal
 or
UserForm1.Show vbModeless"

Into the Form Code or do I need to add it to the Module Code and add buttons.  I'm extremely new at this.


0
GrahamSkanRetiredCommented:
You can put the
UserForm1.Hide (or Me.Hide) in the Useform code.

If you want the user to hide it, a Button on the form is a good idea.

Since the form is not active, you will need to reshow the form from some code external to it, probably from some code in a code module. It rather depends on how your application works and when you need it to be seen again.
0
ghinjerseyAuthor Commented:
So I put:

Private Sub btnCancel_Click()
    btnOkClicked = False
    Me.Hide
End Sub

Private Sub btnOK_Click()
    btnOkClicked = True
    Me.Hide
End Sub

Private Sub btnMerge_Click()
    btnMergeClicked = True
    Me.Hide
End Sub

Private Sub btnShow_Click()
    btnShowClicked = True
    Me.Hide
End Sub

Into the Form Code and Added the Buttons to the User Form.

Now I'm in the Document Form and my current code is:

If btnOkClicked = True Then
        Bookmarks("bkContact").Contact.Text = frmQuestionaire.txtContact
        Selection.EndKey wdStory
        Options.DisplayGridLines = False
        With ActiveDocument.ActiveWindow.View
            .ShowBookmarks = False
            .ShowAll = False
        End With
        Else
        ActiveDocument.Close wdDoNotSaveChanges
    End If
End Sub

Does anyone know where to btnMerge and btn Show code?
0
GrahamSkanRetiredCommented:
You need the variables to be declared as Public and addressed like this:

If UserForm1.btnOkClicked  = True Then
0
GrahamSkanRetiredCommented:
If you show the form modally, you could put the Show before variables are needed:
UserForm1.Show vbModal
 
If UserForm1.btnOkClicked = True Then
        Bookmarks("bkContact").Contact.Text = frmQuestionaire.txtContact
        Selection.EndKey wdStory
        Options.DisplayGridLines = False
        With ActiveDocument.ActiveWindow.View
            .ShowBookmarks = False
            .ShowAll = False
        End With
        Else
        ActiveDocument.Close wdDoNotSaveChanges
    End If
End Sub

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.