[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

User Form Remembers Last Data Input

Posted on 2008-11-11
10
Medium Priority
?
336 Views
Last Modified: 2012-06-27
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!


0
Comment
Question by:ghinjersey
  • 5
  • 3
  • 2
10 Comments
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 320 total points
ID: 22932240
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
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1680 total points
ID: 22932461
If you hide the form instead of unloading it, the data will be retained during the lifetime of the host application session.
0
 

Author Comment

by:ghinjersey
ID: 22932552
How can I hide it?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 320 total points
ID: 22932607
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
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1680 total points
ID: 22932609
UserForm1.Hide

You can show it again with

UserForm1.Show vbModal
 or
UserForm1.Show vbModeless
0
 

Author Comment

by:ghinjersey
ID: 22932678

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
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1680 total points
ID: 22932799
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
 

Author Comment

by:ghinjersey
ID: 22933052
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
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1680 total points
ID: 22933128
You need the variables to be declared as Public and addressed like this:

If UserForm1.btnOkClicked  = True Then
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1680 total points
ID: 22933153
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question