Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Option Explicit vs. Compare Database Statement

Posted on 2002-05-19
4
1,213 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
ID: 7019736
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
ID: 7019748
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
ID: 7019763
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
ID: 7020725
Oops.

Forgot to give you the points.

Regards.

tali
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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.

860 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