Solved

Option Explicit vs. Compare Database Statement

Posted on 2002-05-19
4
1,198 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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