[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VBA: Saving data in a userForm

Posted on 2000-02-23
6
Medium Priority
?
1,285 Views
Last Modified: 2009-07-29
I've noticed that you can save data in controls placed directly on a word document: i.e. text placed in a textBox control on a word document is saved along with the document so that it is still there when the document is reopened.  Like regular Visual Basic, data put into a control on a userForm aparently is not saved when the form is unloaded: i.e. the default properties of the control are set when the form is reloaded regardless of what the user put into the control earlier.  Is there any way to save the inputs on a user form without creating a separate data file or putting the data on the word document itself?  If a separate data file is required, is there any way to encapsulate this data with the word document so the user sees just one (word document) when opening the project?
0
Comment
Question by:SteveW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 2551541
Hi SteveW,

This is for a seperate textfile form where you can load and save data for the formproperties...

http://support.microsoft.com/support/kb/articles/Q197/0/21.ASP?LNG=ENG&SA=ALLKB&FR=0

But you mentioned this was not what you were looking for...

Leaves another possibility open, that of the bookmarks. You could put some hidden bookmarks into the document, where you store data for formfields, and retrieve them from.

If you would like a sample, i'll write one...

HTH:O)Bruintje
0
 
LVL 22

Expert Comment

by:ture
ID: 2553694
SteveW,

Just an idea...

If it's only a few values you wish to remember, and if the values should be saved for the current user/machine, you might find it easy enough to use the registry.

The parameters (all strings) are:
Application, Section, Key and Setting (only when setting the value). Here's an example:

'Write to registry
n = "Ture Magnusson",
SaveSetting "TuredataInvoicing", "OrderForm", "CustomerName", n

'Read from registry
n = GetSetting("TuredataInvoicing", "OrderForm", "CustomerName")

Ture Magnusson
Karlstad, Sweden
0
 
LVL 5

Expert Comment

by:vboukhar
ID: 2564314
Other way - to store your information into custom document properties (like data in TextBox1 in my example):

Private Sub UserForm_Initialize()
On Error Resume Next
' if custom property doesn't exist yet
Me.TextBox1.Text = ThisDocument.CustomDocumentProperties("TB1")
On Error GoTo 0
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
On Error Resume Next
ThisDocument.CustomDocumentProperties.Add "TB1", False, msoPropertyTypeString, Me.TextBox1.Text
ThisDocument.CustomDocumentProperties("TB1") = Me.TextBox1.Text
On Error GoTo 0
End Sub

Hope it helps.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:ture
ID: 2615528
SteveW,

Even better than CustomDocumentProperties is to use document variables. They can contain more data (up to ~60 K strings) and they don't show up when right-clicking a document to see it's properties.

Sub UseDocumentVariables()
  'Create new variable if not already present
  On Error Resume Next
  ActiveDocument.Variables.Add Name:="invoicenumber"
  On Error GoTo 0
 
  'Set value of variable
  ActiveDocument.Variables("invoicenumber").Value = 36500
 
  'Display value of variable
  MsgBox ActiveDocument.Variables("invoicenumber").Value
End Sub

/Ture
0
 
LVL 22

Accepted Solution

by:
ture earned 800 total points
ID: 2615545
Upgrading to answer.
0
 

Expert Comment

by:BegnrSteve
ID: 2628491
Maybe, I don't understand the original question corrrectly, but it sounds as if SteveW was asking about templates which is an easy and completely successful way for the user to use the form and input data to be saved as a document for later retrieval and editing or whatever.  Maybe, SteveW will come back to tell me that this is not an option.  

You folks have provided sufficient answers to his question and the solutions are certainly excellent.  Good discussion here.   ;-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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