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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

global boolian variable question 3

Status
Not open for further replies.

jpl458

Technical User
Sep 30, 2009
337
0
0
US
In an earlier post with replys VPH suggested using a Global Boolian Variable. From what I've read those sorts of things can only exist in a standard module. So I created one that looks like:

Option Compare Database
Option Explicit

Public EventSwitch As Boolean
EventSwitch = False

End Sub

but I get:

Compile Error
Invalid outside procedure

I crawled over the net and am still in the dark, and have tried several versions of a solution.
The way it's to be used is I have a timer event that has a long running query, but the users need to be able to break in. So I am using PHV's suggestion. Just need to know where the Global Boolian variable is created. An example would be a big help.

Thanks again

jpl

 
Hi jpl,

nothing wrong with declaring your variable like this. Just the initialisation must be in a procedure, e.g. in the Form_Load() procedure or the like.
Code:
Sub Form_Load()
EventSwitch = False
...
...
End Sub

Does this help?

Cheers,
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
I did the following:
In the OnLoad event of the form is the following:

Private Sub Form_Load()
EventSwitch = False
End Sub

In the EventSwitchGBL Module Is;

Option Compare Database
Option Explicit
Public EventSwitch As Boolean
EventSwitch = False
End Sub
Also tried it with the EventSwitch = False removed from the module.

Still get Invalid outside procedure.

Thanks

jpl






 

In your Module have just this:

Code:
Option Compare Database
Option Explicit

Public EventSwitch As Boolean
[s]EventSwitch = False

End Sub[/s]

Also, as MakeItSo suggested, you may assign the value to it that way, or rely on its default value, which is False for Boolean when you declare it.

Have fun.

---- Andy
 
I don't think you need a standard code module.
Simply put this line in the Declations section of your form module:
Public EventSwitch As Boolean

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You can do it the way PHV suggests, and if your Form is named frmMyForm (for example) as long as you are in this Form you can just do:
[tt]
EventSwitch = False
[/tt]
but if you want to set the value from other form/module/place, you will need to do:
[tt]
frmMyForm.EventSwitch = True
[/tt]

BTW, I usually name my Booleans with the word 'Is', like blnIsDone or blnFormIsClosed
It's a lot easier to read True / False state of it. But that may be just me... :)

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top