Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access a variable (global?) in any form (MS Access) 1

Status
Not open for further replies.

xenofoob

Programmer
Oct 4, 2004
28
NL
Heya,

Is there any way to access a variable in a form where the variable is not created?

This is my layout (simply explained):

mainform:
Dim bLogin As Boolean

loginform:
MsgBox bLogin (result: empty msgbox)

The mainform is being closed after loginform has been opened.

Is there anyway to access the variable bLogin as a GLOBAL orsomething?

Erik.
 
To create a true public variable, declare it in the declaration section (at the top, right after the option compare database/option explicit lines) of a standard module (not a forms/reports module, but in VBE - Tools | Insert | Module) using the public keyword:

[tt]public gfLogin as Boolean[/tt]

Else, the scope of a form variable is whithin either the routine (sub/function) if it's declared within it, or the form if it's declared in the declaration section (with the public keyword).

If it's declared with the public keyword a forms declaration section, then it is accessible as long as the form is open, just as any form property thru for instance:

[tt]msgbox forms("frmMain").myformpublic[/tt]

For Access questions, perhaps have a look at the Access fora (there's seven of them here...)

Roy-Vidar
 
GREAT!

The solution for my problem was to insert

public gfLogin as Boolean

into the module. Tried this before only without the public.

Thanks for the quick reply ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top