PDA

Click to See Complete Forum and Search --> : Scope of Variables


JohnAtWork
Jan 21st, 2000, 02:56 AM
Prior to saying rtfm, here's the stuff I'm encountering:

I have a module that is loaded first thing when a database opens; inside of it is a variable I declare.

I've tried declaring it in the following two ways:

Dim strVar as string
Public strVar as string

that's neither here nor there; what happens after that is that I wish to call it in a different module (one attached to a form) but it won't compile. Tells me undefined variable!

I don't understand; I've set it up as a public variable in the first module that should be loaded into memory.

Any ideas?

Another quirky thing I've been wondering about it this:
I have a form based on a query. The query relies on a function.
I call the function in the form's Open event, but the form still comes up blank, unless I close it and reopen it.

I worked around it by creating a splash form that calls the data, opens the main form, then closes itself, but I feel like this is a sloppy way to work it.

Any ideas?

MartinLiss
Jan 21st, 2000, 05:20 AM
When you say "Module" I assume you mean "Sub", "Function" or "Procedure" although using "Module" that way is not the normal usage of the word. But enough about that. To solve your problem, add a real code module (Project>Add Module) to your project and move your Public strVar as string statement to it. strVar will then have global scope and will be available anywhere in the app.

------------------
Marty
Can you buy an entire chess set in a pawn shop?