Disappearing variable

S

Sergio Crisalle

I have an AutoExec macro that obtains the name of the
provider who will be using the terminal. The name is
stored in a public variable called "provider" and it is
entered into a note via other macros.

Problem: after a few times the variable is applied to
documents and printed, the variable gets "empty" and no
longer keeps the provider's name.
I'm using Word 2002
Any help will be appreciated.

Public Provider As String
Sub AutoExec()

Provider = InputBox("Please enter your Name and title as
your signature", "Provider Identity")
Who = MsgBox("Please Click File, Open and Select by double
clicking your directory, " + Chr(10) + Chr(10)
+ "corresponding to " + (Provider) + " then Cancel",
48, "Find Your Directory")

End Sub
 
J

Jezebel

There are several events that clear global variables while Word is running.
The most common is doing anything in the VBE environment -- editing a macro
for example. This resets the VBE 'project' which, amongst other things,
clears all variables.

Perhaps a better method for what you're trying to do would be to store the
value in a non-volatile way: in the registry or as a CustomDocumentProperty,
DocVariable, AutoText entry (etc) in normal.dot.
 
W

Word Heretic

G'day Sergio,

unfortunately Jez is a clueless beginner hack whose advice in this
case will lead you astray. Don't store anything in Normal.dot ever.

You can simply set those suggested variables in the document itself,
where it belongs, or the registry.



Jezebel said:
There are several events that clear global variables while Word is running.
The most common is doing anything in the VBE environment -- editing a macro
for example. This resets the VBE 'project' which, amongst other things,
clears all variables.

Perhaps a better method for what you're trying to do would be to store the
value in a non-volatile way: in the registry or as a CustomDocumentProperty,
DocVariable, AutoText entry (etc) in normal.dot.

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 
M

mksmith

Would it be appropriate to get the user's login name for the machine that
they used? If they are logging onto a network then calling the
GetUserName() API could be useful.

If this is the case, then please let me know and I'll knock up some code
for you.

Regards
Malc
www.dragondrop.com
 
S

Sergio

The login name is not the same as the Provider name. The
network uses the user’s initials and employee number,
instead of their full names.
Thanks I already have the code for obtaining the user
name. Since the templates are stored in the network under
a private folder called like the user’s name, and only
available to administrators and the user himself, when I
distribute new templates I get their user name assign it
to a variable that becomes part of the path to copy the
files to their folder.
My problem is that the macros do not open vba or change
anything, and the Provider variable becomes “empty” every
now and then. Some days it runs flawlessly the entire
session. Some other days, it keeps the Provider’s name
perhaps six times or less.
The Program is used in the following way:
A user starts Word, and enters his/her name. This name is
kept in the Provider variable (public). They are health
care providers. After they see a patient they create a
document from a template that enters their name at the
bottom for the signature and identification (simple
macro). Very straight forward, no other interaction
happens. We are using Word 2002 on a Windows NT network.
On IBM Pentium II machines with 256 K RAM
What could cause the variable to behave so erratic?
 
M

mksmith

The only clue there is the size of the RAM; perhaps it's making the thing
vanish.

As a possible work around; you tell me that the templates are stored on
the LAN, each user's templates being held in a folder which reflects their
name. Is this the same name as what is being held in the variable? If
so, a very gruesome hack would be to extract the variable from the
workgroups folder, or whichever you have defined it to be.

But if this continues then I would suspect memory. Now, the normal.dot
templates aren't shared are they?

The only other thing that strikes me is that 'Provider' could be a
reserved word or something. In the meantime, if you change it to
'gsProvider' (global string called Provider) then that won't do any harm.

Malc
www.dragondrop.com
 
S

sergio.crisalle

The only clue there is the size of the RAM; perhaps it's making the thing
vanish.

As a possible work around; you tell me that the templates are stored on
the LAN, each user's templates being held in a folder which reflects their
name. Is this the same name as what is being held in the variable? If
so, a very gruesome hack would be to extract the variable from the
workgroups folder, or whichever you have defined it to be.

But if this continues then I would suspect memory. Now, the normal.dot
templates aren't shared are they?

The only other thing that strikes me is that 'Provider' could be a
reserved word or something. In the meantime, if you change it to
'gsProvider' (global string called Provider) then that won't do any harm.

Malc
www.dragondrop.com

I came across this thread after 13 years and realized I never responded to it.
I solved the issue back then by writing the provider's name to a text file and then assign its value to the signature field. The text file is overwritten every time a user starts word. Somewhat rudimentary solution but it did the job.
 
S

sergio.crisalle

The only clue there is the size of the RAM; perhaps it's making the thing
vanish.

As a possible work around; you tell me that the templates are stored on
the LAN, each user's templates being held in a folder which reflects their
name. Is this the same name as what is being held in the variable? If
so, a very gruesome hack would be to extract the variable from the
workgroups folder, or whichever you have defined it to be.

But if this continues then I would suspect memory. Now, the normal.dot
templates aren't shared are they?

The only other thing that strikes me is that 'Provider' could be a
reserved word or something. In the meantime, if you change it to
'gsProvider' (global string called Provider) then that won't do any harm.

Malc
www.dragondrop.com

I came across this thread after 13 years and realized I never responded to it.
I solved the issue back then by writing the provider's name to a text file and then assign its value to the signature field. The text file is overwritten via the input box every time a user starts word. Somewhat rudimentary solution but it did the job.
 

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