"Option Explicit" not working? (1 Viewer)

DataMiner

Registered User.
Local time
Today, 12:15
Joined
Jul 26, 2001
Messages
336
I have several modules in the same database. ALL of them start with

Option Compare Database
Option Explicit

I always use Option Explicit, and depend on it to save me lots of headaches.

However, in some modules it doesn't seem to work! I can put in all the undeclared variables I want, and it never complains. Then after awhile, I know not why, it will start complaining about them.

Has anyone else seen this? Any ideas?
 
Try compiling your modules (under Debug menu). This should find any modules using Option Explicit with undeclared variables.

HTH
 
Well, that's the problem I'm talking about.... it doesn't! I can put in all the undeclared variables I want, and compiling causes no complaints. I can even set variables equal to incompatible values, declare the same variable more than once, etc... and compile without getting any errors.

Things will stay this way for awhile... so I've compiled and am under the impression that everything is fine... and then later it will start complaining about the undeclared variables.
 
Check out the menu:

Tools-> Options -> Editor (tab)
Make sure "Require Variable Declaration" is checked

Tools -> Options -> General (tab)
Make sure "Compile on Demand" and "Background Compile" are checked
 
Yes, all of this stuff is checked. Also, note that this was happening in one module in the database, but not in others in the same database.
 
Import all of the db objects into a new database.
 
Ok, so your saying it's just another one of those unexplained 'corruption' issues? I'm sure that will fix it; as I said, it almost always goes away on it's own after awhile anyway. Problem is, I need it not to happen in the first place! This seems like a pretty major bug for those of us depending on "compile" to warn us of undeclared variables BEFORE we release a database to production! Sort defeats the purpose of "Option Explicit" in the first place, if it's not going to work dependably.

Sorry, I know I'm probably preaching (or ranting, as the case may be) to the choir here. How do you suppose we get Microsoft's attention on issues such as this?
 
You don't.

They have more important problems then this. Mostly dealing with data security. Search this thread on "decompile" and do that before you copy everything over.
 
Thanks for your recommendations, but I'm not interested in pursuing a one-time fix, only interested in finding a way to keep this (thinking my db is OK, releasing it, and then having it crash due to undeclared variables) from happening in the future. Guess I just have to be more careful to check for undeclared variables myself; either that, or remove the "option explicit" before I release to production.
 
Why not post your db for others to examine. Just post a good module and a bad module. Remove what you do not want anybody to see. Only way to tell if it is your db or your pc [installation of Access].
 
Try doing a "Repair" on MS Office.

Under the Add/Remove Programs, click on "Change" under Microsoft Office - this will bring up an option to repair your installation. If the assumption that something is corrupt, this may solve it.

HTH
 
DataMiner said:
Thanks for your recommendations, but I'm not interested in pursuing a one-time fix
Too bad.

only interested in finding a way to keep this (thinking my db is OK, releasing it, and then having it crash due to undeclared variables) from happening in the future
Write a better db program/get a better computer

Guess I just have to be more careful to check for undeclared variables myself; either that, or remove the "option explicit" before I release to production.
Why would you want to remove Option Explicit? It is there to help you, to make sure you declare all of your variables. I, personally, have never had this problem or even seen this problem, which makes me believe you're not doing something right.

If you want to always use Option Explicit in all your procedures, you can have Access do it for you by checking the "Require Variable Declaration" on the Editor tab of the Tools->Options menu.

If you're putting in "Option Explicit" manually... make sure it is in the GENERAL DECLARATIONS section of your code and then compile your database for changes to take effect.
 
The only reason I'd want to remove "option explicit" is because if I can't depend on it to reliably warn me about undeclared variables BEFORE I release my application, I certainly dont want it to crash my application due to undeclared variables AFTER release. Can't see that "option explicit" does anything for a db other than when it's in development.

About posting an example of the problem... well, the next time I see it, I will do that. However, it's intermittent and has disappeared for now.
 
And you're sure its in the General Declarations portion of all procedures/forms
 
Yep. As you suggest, I have always had the "Require Variable Declaration" on the Editor tab of the Tools->Options menu checked.
 
DataMiner, the Access team really is interested in problems like this. I have never experienced it and it sounds like no one else has either. But that's the way it is with a lot of corruption issues. If you have followed all the advice regarding how to fix the corruption, it is unlikely to recur. However, should it recur, save the database, remove any sensitive data, and send it to Microsoft with as detailled an explaintion as you can write. I have gotten real responses when I have contacted Microsoft about bugs. If you want me to, I can forward it to the correct people. I have several contacts on the actual development team.
Here's a link to their "connect with Microsoft" page - http://www.connect-ms.com/msts2/
 
Pat,
Thanks a bunch... I will definitely do as you suggest.
 
Pat,
They're interested in problems like this, but more than likely this is more of an error with his own machine rather than the program. Because this is a spontaneous error, I don't think they concentrate on fixing bugs like this. They generally have their hands full and concentrate on problems that the majority of people have. At least, I believe that's what my friend on the Windows development team says.

Corruption is a difficult study and a lot of the times has to do with how software is acting with hardware, or the quality of the hardware (most often the memory and cache).

But the good thing about sending it in is that if they do fix it, it could possibly fix other related errors generated in the application, or they could stumble across a solution to other problems.

In any case, Pat is a bridge player. :)
 
Courtesy bump.

I found this awesome solution on an Excel forum:

Gates Is Antichrist said:
solved - after 30 other insane inexplicable theories -

I added a space, hit enter, then delete from the end of line Option Explicit. It fixed it.


If * I merely hit enter, then delete from the end of line Option Explicit. This did NOT fix it!!! (Tried before the above solution.)

One of the most beautiful bugs I've had the pleasure to encounter.


Footnotes:
* An "If" was added to paragraph 3 by JoelAnthony333 for grammar purposes.

Edit:
P.S. I am hoping to win my 3rd NBA Championship with the Miami Heat in 2013-2014.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom