Solved Option Explicit?

I think every time you need to recompile, such as editing a line of code and saving it as the trivial example, Option Explicit gets considered. However, VBA in Access is compile-on-need, not necessarily every time you launch a form or report. If you compiled a module and have not made any changes, it doesn't compile again on launch. (Of course, if you DID edit the module to include "Option Explicit"... that IS a change to the code!)
Bingo!.. That's what I thought. It's a Pre Compiler Directive.
 
Last edited:
I find something has not been declared. I add Option Explicit, and then it does not compile, which you would expect.
Bingo!.. That's what I thought. It's a Pre Compile Directive.

Just to be clear. The Option Explicit directive itself affects only the module you put it in. So, if you take an old db and change the default, nothing in the existing modules changes. You must manually add the directive to every module in the database and then of course, compile and fix all the errors..
 
However, VBA in Access is compile-on-need, not necessarily every time you launch a form or report
Just as an aside, I have a db where I experiment with code, forms, sql etc. must be over 20 years old (or at least old code etc) as it was upgraded from 2003 to 2010 15 years ago.

Now I have moved to 64bit access, if I create a simple test form with a bit of code behind an event and try to open it, the compiler tells me some api’s in another module (which I’m not using) are not 64bit compliant.

Implication being that the whole project is compiled on form open - or perhaps just reviewed?
 
IIRC, by default, the vb.net and vb6 compilers enforce explicit variable declaration?

Without using Option Explicit you could unintentionally declare a new variable by accidentally misspelling an existing variable name. That happened to me when I was learning to write vba code, and I consumed a lot of time trying to figure out what was wrong.
 
IIRC, by default, the vb.net and vb6 compilers enforce explicit variable declaration?
I'm not entirely sure about VB6, but I think it does.
A definite Yes for VB.Net. And it's a compiler option that applies to all files in a project. You don't need to put the Option Explicit statement in any file unless you want a particular behavior for one specific file overriding the global option.
 
However, VBA in Access is compile-on-need, not necessarily every time you launch a form or report.

Although that is the default, it depends on the VBE settings

1753812520214.png


From the VBE Options help:
Compile On Demand: Determines whether a project is fully compiled before it starts, or whether code is compiled as needed, allowing the application to start sooner.

Background Compile: Determines whether idle time is used during run time to finish compiling the project in the background. Background Compile can improve run time execution speed. This feature is not available unless Compile On Demand is also selected.
 

Users who are viewing this thread

Back
Top Bottom