Saving & Restoring Form Information

A

axeman

Is there any way to save the user input so that next time a user runs the app
it pops up with the information they entered last time in all the fields???

Thanks,
Axe
 
J

Jean-Guy Marcil

axeman was telling us:
axeman nous racontait que :
Is there any way to save the user input so that next time a user runs
the app it pops up with the information they entered last time in all
the fields???

???
More details are needed. What app are you talking about? What kind of
fields? What is the context? Word version?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Dawn Crosier

I would store the information in Document Variables if you want the
data available for repeat running.

Here is some sample code which will check to see whether a variable
exists, if not it will help you to create one, and add a value to it.

'Test to see whether document variables exist if not add then

If DocVarExists("varClientName") Then

ActiveDocument.Variables("varClientName").Value = "test"

Else

ActiveDocument.Variables.Add Name:="varClientName",
Value:="test"

End If



'Function used to check to make sure the Document Variable exists
because

'If you try to add it, and it does not exist - an error will be
returned.

'Same is true if you try to set its value and it does not exist.

Function DocVarExists(strVarName As String) As Boolean

Dim varDocVars As Variant



DocVarExists = False

For Each varDocVars In ActiveDocument.Variables

If varDocVars.Name = strVarName Then DocVarExists = True

Next varDocVars



End Function



To retrieve a Document Variable for use

= ActiveDocument.Variables("varVersion").Value



To update a Bookmark based on a result from code

ActiveDocument.Bookmarks("DateOfLetter").Range = _

ActiveDocument.Variables("varVersion").Value



I hope this helps.


--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.
 
J

Jean-Guy Marcil

Dawn Crosier was telling us:
Dawn Crosier nous racontait que :
I would store the information in Document Variables if you want the
data available for repeat running.

Here is some sample code which will check to see whether a variable
exists, if not it will help you to create one, and add a value to it.

Just thought I'd mention to those interested with "short" code that you do
not need to check for existence if you want to create a document variable:

ActiveDocument.Variables("varClientName").Value = "test"

will create it if it does not exist, and

ActiveDocument.Variables("varClientName").Value = ""

will effectively delete the variable.

You still have to check if it exists if you want to read the variable
though.

ActiveDocument.Variables("varClientName").Value = ""
MsgBox ActiveDocument.Variables("varClientName").Value

will generate an error.
'Test to see whether document variables exist if not add then

If DocVarExists("varClientName") Then

ActiveDocument.Variables("varClientName").Value = "test"

Else

ActiveDocument.Variables.Add Name:="varClientName",
Value:="test"

End If



'Function used to check to make sure the Document Variable exists
because

'If you try to add it, and it does not exist - an error will be
returned.

'Same is true if you try to set its value and it does not exist.

Function DocVarExists(strVarName As String) As Boolean

Dim varDocVars As Variant



DocVarExists = False

For Each varDocVars In ActiveDocument.Variables

If varDocVars.Name = strVarName Then DocVarExists = True

Next varDocVars



End Function



To retrieve a Document Variable for use

= ActiveDocument.Variables("varVersion").Value



To update a Bookmark based on a result from code

ActiveDocument.Bookmarks("DateOfLetter").Range = _

ActiveDocument.Variables("varVersion").Value



I hope this helps.


--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

axeman

How would this work for a userform that I want to restores the values of the
fields every time that the application is run. Basically, the user inputs the
information and closes out of the application once they are finished with
their processing. Then the next time that they run the app the information
they typed in last is automcatically populated in all the fields.

Thanks,
Axe
 
C

Charles Kenyon

Store the information in your document/template as document variables and
save. When userform is used again, have it check for existence of variables
and if present, use those values.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

sc

I need help with naming and declaring a variable to store string data in
textboxes, then saving that data, so that when the program is opened at a
later time, the data is still there. I don't understand what you have said so
far about checking for the existence of variables. Why can't a person just
name and declare a variable for the data, then save it? I have 6 forms. On
Form1, there are 5 textboxes. I want to save the user input to these
textboxes, so it is there when the program is reopened later. How can I do
that?
 

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