How to make abc : variant can be used everywhere ??

M

Martin

I want to dim a variant(for example: abc) which can be used in every sub (
can be used in everywhere of an Access engine).

Question:

How to do? ( public? for example) Where to put this dim? Please kindly
give me an example.


Thank you very much!


Martin
 
P

peregenem

Martin said:
I want to dim a variant(for example: abc) which can be used in every sub (
can be used in everywhere of an Access engine).

A global variable with a vague name which can hold anything and
everything? This doesn't sound like great software engineering to me.
Take a look at a professional object model e.g. the Access object model
in the Visual Basic Editor's Object Browser (hint: it has an
Application class with strongly-typed public properties with meaningful
names).
 
M

Martin

Yet, I still don't know how to do.


A global variable with a vague name which can hold anything and
everything? This doesn't sound like great software engineering to me.
Take a look at a professional object model e.g. the Access object model
in the Visual Basic Editor's Object Browser (hint: it has an
Application class with strongly-typed public properties with meaningful
names).
 
A

Allen Browne

1. Select the Modules tab of the Database window.

2. Click New. Access opens a new code window.

3. At the top, just below the Option statements, enter:
Public abc As Variant

You can now use this variable in any part of your project. For example you
could set it in the click of a button on one form, and change it in another
routine elsewhere, so if you run the first routine again the value has
changed.

Pretty unreliable, and in general to be avoided at all costs, but that's how
it's done.
 
A

Albert D.Kallal

You just need to create a standard code module.

If you declare the variable as public, then all routines, and all modules
can use the variable.

Public strUserName as string
can be used in everywhere of an Access engine.

That is a bit different. Do note that variables that you declare can NOT be
used in sql, or forms "expressions". So, you can use the above variable
anywhere in code, but to use it in a control on a form, or in a report, or
in sql, you can't use the variable. However, you CAN use a declared function
virtually anywhere in ms-access.

So, you can declare a public function, and that CAN be used virtually
anywhere

Public Function MyUserName() as string

MyUserName = strUserName

end function

Now, you can place a text box on a form, and put as the data source for the
text box the function name

=MyUserName()

You could also use the above expression in a report, and the also in sql
expressions..

Do note that any un-handled error in ms-access will re-set both local, and
global vars. If you distribute a mde, then un-handle errors will NOT reset
those variables.
 
Top