LadyDi
02-22-2008, 12:44 PM
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.
gemma-the-husky
02-22-2008, 01:00 PM
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
LadyDi
02-25-2008, 04:24 AM
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?
Moniker
02-25-2008, 05:50 AM
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.
Call_Me_Sam
02-26-2008, 02:59 AM
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..