Solved

Option Explicit vs. Compare Database Statement

Posted on 2002-05-19
4
1,153 Views
Last Modified: 2006-11-17
Hello everyone,

I used the Access Performance Analyzer on my application and the only suggestion it offerred was to use an "Option Explicit Statemant" at the beginning of the declaration section of the code behind my forms and reports, in order to make my code run faster

All of the code behind my forms currently begins with

"Option Compare Database"  statement.

In order to follow the advise of the analyzer should I insert the "Option Explicit" statement after the "Option Compare Database"  statement OR should I replace the "Option Compare Database"  statement with the "Option Explicit" statement?

All of the variables in my modules are explicitly defined.

Any comments would be much appreciated. (Ie any negative side effets, implications to using the Option Explicit Satement etc...)

Thanks

tali
0
Comment
Question by:travisali
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Bob Scriver earned 100 total points
Comment Utility
You should remove the Option Compare Database statement and replace it with Option Explicit.  

This forces you to declare your variables before using them and also helps you by providing for a syntax error at compile time if a variable, function, sub is not already declared.  Typos will be found at compile time thus saving you much debugging problems.

ACCESS Help statement for Option Explicit:
If used, the Option Explicit statement must appear in a module before any procedures.

When Option Explicit appears in a module, you must explicitly declare all variables using the Dim, Private, Public
, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs at compile time.

If you don't use the Option Explicit statement, all undeclared variables are of Variant type unless the default type is otherwise specified with a Deftype statement.

Note   Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear.

ACCESS Help:
Option Compare Database can only be used within Microsoft Access. This results in string comparisons based on the sort order determined by the locale ID of the database where the string comparisons occur.

I hope this helps you.

Bob scriver


0
 

Author Comment

by:travisali
Comment Utility
Many thanks once again Bob.

That's exactly the answer I was looking for.

Just to let you know that I'm not a completely out to lunch. I did check access help and got the same file you just reproduced. Help says to place the stamement before any "procedures" I did not know what this meant in relation to the "Option Compare DataBase".

Have a great day.

tali
0
 
LVL 3

Expert Comment

by:Bob Scriver
Comment Utility
Wasn't implying the "out to lunch" issue.  Just a little lazy and wanted to be thorough.  Cut, copy and paste gets the job done sometimes.

Wanted you to have all the information necessary to fix your problems.

Bob Scriver
0
 

Author Comment

by:travisali
Comment Utility
Oops.

Forgot to give you the points.

Regards.

tali
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now