Set variable "locally" so Global Template form can read it

C

Chris

I want to establish a variable that carries a value specific to the
user (the user's location in the building) so I can use that value in
a form contained in a shared template. The form helps the user format
documents and print them, depending on what printer they're printing
to, hence the need to establish the variable.

I just can't figure out how to do it, where to declare the variable
(normal.dot?), how to reference it in the shared form. I've tried
every which which way, read every newsgroup suggestion I can get my
hands on, read MSDN's reference material, you name it... I'm stuck.

How to?
 
J

Jay Freedman

Hi Chris

I'll suggest that the best place to store the data is in the user's
registry. As part of installing your template on their machine, run a
little macro that lets you type in the location in an InputBox and
then writes it to the registry like this:

Sub RegisterLocation()
System.PrivateProfileString("", _
"HKEY_CURRENT_USER\Software\Jaysoft\Internal Settings", _
"Location") = InputBox$("Enter location:")
End Sub

[Use your own company name.]

Your form can retrieve the data like this:

Sub RetrieveLocation()
Dim Location As String
Location = System.PrivateProfileString("", _
"HKEY_CURRENT_USER\Software\Jaysoft\Internal Settings", _
"Location")
MsgBox Location ' use Location as needed
End Sub

Of course, you'll want some error-trapping. For example, if the
registry key or the value doesn't exist, the retrieval function will
return an empty string. "" (length = 0), so then you'd either put an
error message and exit from the macro, or assume a reasonable default
value.
 

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