Public Variables

G

Guest

Hi

I store the company name that is displayed on all my forms in a table. I use
DLookup("[Company Name]", " Company Details") to retrieve the company name
from this table. Is it not better to retrieve the company name at startup
and store it to a global variable?

If the variable option is the best, how do I declare a global variable in
Access? I declare the variable in a module but can not get a value assigned
to it.

As you can see I am new at this.

Kind Regards

Pierre
 
D

Douglas J Steele

Nothing wrong with repeatedly looking it up (unless you have to do it an
inordinate number of times).

A disadvantage of global variables is that they can get reset when an error
occurs.
 
G

Guest

Thank You for your response

Where can I learn how to use a public Variable?

It is driving me up the wall.

Kind Regards
Pierre

Douglas J Steele said:
Nothing wrong with repeatedly looking it up (unless you have to do it an
inordinate number of times).

A disadvantage of global variables is that they can get reset when an error
occurs.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Pierre said:
Hi

I store the company name that is displayed on all my forms in a table. I use
DLookup("[Company Name]", " Company Details") to retrieve the company name
from this table. Is it not better to retrieve the company name at startup
and store it to a global variable?

If the variable option is the best, how do I declare a global variable in
Access? I declare the variable in a module but can not get a value assigned
to it.

As you can see I am new at this.

Kind Regards

Pierre
 
D

Douglas J Steele

You need to declare public variables in a module (not a module associated
with a form).

You declare them as:

Public MyPublicVariable As String

You can then use that variable anywhere in your VBA code.

Note: You cannot use public variables in SQL statements (but then, you can
use any variables in SQL statements). If you want to use the value of a
public variable as a criteria for a query, say, you need to create a
function that returns the value of the public variable, and use the
function:

Function MyPublicVariableValue() As String
MyPublicVariableValue = MyPublicVariable
End Function


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Pierre said:
Thank You for your response

Where can I learn how to use a public Variable?

It is driving me up the wall.

Kind Regards
Pierre

Douglas J Steele said:
Nothing wrong with repeatedly looking it up (unless you have to do it an
inordinate number of times).

A disadvantage of global variables is that they can get reset when an error
occurs.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Pierre said:
Hi

I store the company name that is displayed on all my forms in a table.
I
use
DLookup("[Company Name]", " Company Details") to retrieve the company name
from this table. Is it not better to retrieve the company name at startup
and store it to a global variable?

If the variable option is the best, how do I declare a global variable in
Access? I declare the variable in a module but can not get a value assigned
to it.

As you can see I am new at this.

Kind Regards

Pierre
 

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