Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 807
  • Last Modified:

Option Compare Database and Option Explicit

On a number of the modules behind my forms it starts with:
Option Compare Database
Option Explicit

From what I understand this seems to be a good practice for the beginning of all modules with this though I am not 100% sure why. I see Option Explicit as a way to for the module to pick up on any typos in declarations.

I suppose first I would like to get clarification on the purpose of this code and also know if it is worth opening all the modules and inserting this if it is not already there.
0
Shawn
Asked:
Shawn
  • 6
  • 4
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"and also know if it is worth opening all the modules and inserting this if it is not already there."
Just an FYI ... for a *new* Module ... you can have it automatically add Option Explicit:

Auto add Option Explicit
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
From Help:
"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.

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"


Option Explicit is DEFINITELY best practice.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
To not reinvent the wheel ... look up Option Compare in VBA help ... it gives a full explanation of what this means ... basically determining the comparison method to use when string data is compared.
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
ShawnAuthor Commented:
ok, pretty sure it's clear now.

The wierd thing is as you know I've set up vbWatchdog (amazing btw) and on my login form I added this:
Private Sub Form_Load()
Call ErrEx.Enable("OnError")
End Sub

When opening the db and the login form loads I got the error on load...file not found.
I noticed in this module I did not have..."Option Compare Database and Option Explicit", added it. Closed the db, opened and presto, no more error.

I can't figure out the relation between this error and the option compare/explicit.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Humm ... must have to do with Option Compare. W/O that statement, the default is Option Compare Binary - not Database .... but still.

You might want to run this by Wayne ...
0
 
ShawnAuthor Commented:
ok, will do. Bug is gone but bizarre. I'll let you know what he says.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
yes ... please do.
thx
0
 
ShawnAuthor Commented:
doesn't seem there is a relation but he confirms a suspicion I've had for a while...

Wayne's response: "That error is quite a well known indicator that the module behind the form has somehow become corrupt (specifically, the compiled form of the module).  It's not a problem specific to vbWatchdog though, just a minor problem with the VBA compiler itself that sometimes occurs.

Another way to fix problems like that, is to use the decompile switch in Access, which clears out all the compiled code in your project, ready for re-compilation."

As I have decompiled recently I think I'll opt to redo the form. It's only a small one.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Well, this makes sense.  Corruption is certainly a possibility.

I would have no fear of decompiling again ... just make a back up first.
0
 
ShawnAuthor Commented:
decompiled and no error as of yet. thx!

if you have a minute :)
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_28017619.html#a38847262
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now