Link to home
Start Free TrialLog in
Avatar of gixxer1020
gixxer1020Flag for United States of America

asked on

Retaining the information in a Userform

I have a Userform with textboxes that place information into a document using bookmarks, some of the textboxes have information used only for calculations in the Userform and are not placed in the document, so everytime the Userform is initialized those textboxes are empty and the information has to be re-input. How can I retain the information for the textboxes that do not place information into the document in the Userform so I won't have to re-enter that information each time the document is closed & opened?
Avatar of Joanne M. Orzech
Joanne M. Orzech
Flag of United States of America image

In VB Editor, click on the text box you want the information to appear in, under properties (View, Properties), scroll to text, type in the text you want to appear.

HTH
or... another way:  On document open you could put:

Sub Document_Open()
     frmMain.TextBox1.Value = "5"
     frmMain.Show
End Sub



Avatar of gixxer1020

ASKER

I don't want a default set of information in the textboxes, just to retain the information that was last placed in the textboxes. I read something about using arrays, but I'm not sure how to set-up, store & retrieve information in & out of an array? Is that the way to go??
Then you could either write the values to an ini file or write to the registry.
don't use arrays much
Avatar of Sparky191
Sparky191

Any information in an array will be lost once word or that doc is closed. Is that what you want?

If you want keep the information, then you need to create another file to hold that data. You can use an XML file, a database, an ini file, the registry, excel file, a plain text file ot even another word document. Which is best depends on how you want to use that data from then on.

Why is the information not saved to the text boxes? Is it confidential, or do you just not want the users to have to clear the textboxes manually?
No, i want the information to be there when the document is re-opened.
Currently I have information stored in the bookmarks in the document, but I don't know how to save the information in the textboxes that are not used in the document.
Is there apiece of code that will save the information in teh textbox even after the document is closed? If not, how can I save & retrieve the information in hte registry?
Ok. If it was me I'd avoid using the registry if possible.I'd store all the data in one place.  I'd create a hidden section in the actual document, perhaps a protectected section at the end of the document and write the data from the text boxes there on closing the document. Perhaps in a table of some kind. (Note: You can't run any code once the document is acutally closed)  Then on opening the document I'd read in the values from the table into the user forms again. Rewriting the data to the table one closing it a second time. Etc.
ASKER CERTIFIED SOLUTION
Avatar of Joanne M. Orzech
Joanne M. Orzech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Handy code there JOrzech Cheers!

I'll hang on to this myself. I never get around to doing this in my templates and I really should.
Yes - it is quite handy!  Thanks Sparky :)