Solved

Option Explicit vs. Compare Database Statement

Posted on 2002-05-19
4
1,235 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
[X]
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
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

734 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