Option Explicit

LadyDi

Registered User.
Local time
Yesterday, 22:28
Joined
Mar 29, 2007
Messages
894
I have a couple forms in my database that are slow to open. When I ran the analyzer, it suggested that I use an "Option Explicit" statement in my code. What does "Option Explicit" do and where should I put it? You have helped me so much with my databases, I would also like your opinion as to whether or not you think "Option Explicit" is a good solution to slow forms.
 
at the top of each form

it forces you to declare variables before you use them, which is a good discipline, and helps prevent very hard to find errors

probably you set it in tools/options

eg in A97 its module/require variable declaration

if its set when ever you open a new code module the statement "option explicit" will be at the top of the module
 
I cannot find a place on the "Tools / Options" menu to select Option Explicit. What do you mean put it at the top of the form? Does it go in the "On Open Event" VBA code behind the form? You also mentioned something about Modules. I do not have modules in my database. Is that somthing that should be added to help the database move faster? If so how do you go about writing modules?
 
Option Explicit goes at the top of the code for every module. As already mentioned, it forces variable declaration. To have Access write this line for you, it's in Tools -> Options from the code window. The second checkbox down is Require Variable Declaration. That's the one to check.

After checking that, new modules (in forms or standard modules) will look like this at the top:

Option Compare Database
Option Explicit

--- code starts here ---

You can just type in Option Explicit as well.
 
I cannot find a place on the "Tools / Options" menu to select Option Explicit. What do you mean put it at the top of the form? Does it go in the "On Open Event" VBA code behind the form? You also mentioned something about Modules. I do not have modules in my database. Is that somthing that should be added to help the database move faster? If so how do you go about writing modules?

LadyDi, my understanding of Option Explicit is that yes it forces you to declare variables when using procedures, and that by not declaring them Access is forced to assume what data type you might have been thinking of, in doing so it slows down the processing of the code.

You might not actually have stand alone 'modules', but any form or report can have a module where it's specific code is held. so if you have a button on a form, with an OnClick event, then that will have a module...You may have created a the module with an empty event, and the analyser is picking up the fact the module is there..

Hope this helps..
 

Users who are viewing this thread

Back
Top Bottom