Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Option Explicit vs. Compare Database Statement

Posted on 2002-05-19
4
Medium Priority
?
1,328 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 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

636 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