Saving persistent values for later use (sort of cookie)

L

liz

I have some templates whcih use the same information for a user, at
least most of the time. the idea is that the user can select to save
his details for later reuse. This is done using a check box on a
userform associaed with the template. I decided that the best thing to
do woudl be to save the values in the user's Normal template, since
this is their private template. So logically the macro in any template
where this is applicable should do this:

If saveforlater = true
if field(s) don't exist in normal.dot
create them
end if
update field(s) in Normal.dot using entered details (from user
form)
save normal.dot
end if

My questions are this:

1. if I refer to "Normal.dot" will Word find it wherever it is (some
users having it in odd places). I am assuming the answer is yes since
it will be open and therefore Word must know about it. Otherwise do I
need to refer to the full file location and how do I find that out.

2. Since Normal is open, because Word does this on load how do I save
it? I thought the code would be something like this:

"Normal.dot".CustomDocumentProperties.Add _
Name:="test01", _
LinkToContent:=False, _
Value:="<empty>", _
Type:=msoPropertyTypeString

but this causes a complaint because of Normal being open.

thank you.................. liz
 
D

Doug Robbins - Word MVP

Check out the use of the System.PrivateProfileString

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

liz

Check out the use of the System.PrivateProfileString

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Doug,

Thank you, I was avoiding this because I understood from some other
reading that PrivateProfileString doen't work consistently and is
avioded by other experts. Therefore I thought using Normal was a more
reliable solution and also it means that the user can inspect his own
settings. So if there's a way to use it I'd rather.

Any other advice on the original questions?

thanks............... liz
 
J

Jonathan West

I have some templates whcih use the same information for a user, at
least most of the time. the idea is that the user can select to save
his details for later reuse. This is done using a check box on a
userform associaed with the template. I decided that the best thing to
do woudl be to save the values in the user's Normal template, since
this is their private template. So logically the macro in any template
where this is applicable should do this:

If you want to store small quantities of per-user information, then I would
recommend using the GetSetting and SaveSetting commands, which store
information in the user portion of the registry.

I would recommend not using the PrivateProfileString property. I have found
that occasionally it seems to throw an error for no good reason. If you want
to use an INI file to store information, look up Karl Peterson's class
module which reads and writes INI files.

http://vb.mvps.org/samples/project.asp?id=kpIni
 
D

Doug Robbins - Word MVP

Well, I have never had a problem with it, but Jonathon says that he has.
Anyway, there are certainly more ways than one to skin a cat, but I would
say that using the Normal.dot template as you had originally suggested would
not be one of the better ones.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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