Form Option Declarations

gray

Registered User.
Local time
Today, 22:34
Joined
Mar 19, 2007
Messages
578
Hi

Quick question please. I want to make sure my variables are all declared but I don't want case sensitivity... i.e. I want to turn case sensitivity off.... I tried this

Option Explicit
Option Compare Text

This seems to turn off case sensitivity OK but it allows variables to be implicitly assigned.

What Option settings should I have please?.. the correct combination is not easy to find.

Thanks
 
This seems to turn off case sensitivity OK but it allows variables to be implicitly assigned.
Implicitly assigned or implictly declared?

And what do you mean by case sensitivity? The Compare option is for string comparisons.
 
Option Explicit
Option Compare Text

Should do exactly what you require.
Can you give more code to demonstrate your problem?

Chris.
 
Hi

Sorry, yes, I should have said i want them explicity declared (as opposed to implicity declared when assigned).

if possible, I prefer to switch case sensitivity off for everything...

thnx
 
As mentioned by Chris and speakers_86, Option Explicit is what you need for this to be enforced.

But, when last did you Debug > Compile your code? And when last did you Compact & Repair your database?
 
Hi

Actually, I have just done a compact and repair and the Option Explicit is now being enforced thanks.

Odd that the Compare Text worked immediately but the Explicit didn't... Another mystery..

All is OK now, thanks for your assistance everyone.
 
It's quite necessary to perform those two operations regularly when you're developing. Debug > Compile alone could have fixed the problem. I would advise you make a habit of at least Compiling your code regularly.

Happy developing!
 
what does this do

Option Compare Text

I use option compare database with no problems.
 
As has been said, Option Explicit is all you need for this. By default, Access is Case Insensitive! You have to actually work at making it Case Sensitive, if you should need that!

Linq ;0)>
 
what does this do

Option Compare Text

I use option compare database with no problems.
That's case sensitive string comparison within the module it's declared. The default (I think) is Binary if nothing is declared.

I would still include Option Compare Database so that it uses the Locale settings.
 
what i meant was that my modules come up with

"option compare database" by default.
 
Hmmm... I'm getting confused now... so here's my experiemce.

My modules came up with option compare database by default (or at least I didn't set it).

When I wanted to check my Vars I changed it to Option Explicit. At this point it was discovering undeclared Vars but references to some textbox names kept failing -

IF my_textbox.name = "fred" then blah blah

They were failing because my_textBox.name was actually "Fred" i.e. mixed case.

When I added Option Compare Text (so both options set),

IF my_textbox.name = "fred" blah blah

worked again??
 
Compare and Explicit perform two different functions. They are independent of each other.

Option Compare XXX is basically specifying how text should be compared within that module.
Option Explicit enforces strict variable name declaration.

With Option Compare Text you get case-sensitive text comparison.
With Option Compare Database you get case in-sensitive text comparison based on your Locale ID.
There's another Compare option wich Option Compare Binary which you don't need to worry about.

I hope this all makes sense.
 
There are a couple of reasons Option Compare Text, and not Option Compare Database, may be used in a module.

1.
The code may be a copy/paste from another application other than Access. As far as I know only Access uses Option Compare Database.

2.
Someone, like me, may have changed Option Compare Database to Option Compare Text because of the following:-
http://www.trigeminal.com/usenet/usenet001.asp?1033

Now people may say that that is an old bug in an old version which should have been fixed by now. Well, perhaps it has been fixed, I don’t know, but even if it has been fixed that does not mean people are running a fixed version.

So when I write demos for the Sample Database Forum I change Option Compare Database to Option Compare Text. However, I do not think we can recommend either under all circumstances.

Chris.
 
Interesting bug Chris.

I wonder if the developers are aware of this and provided a patch in later releases.
 
Before we start any mass panic about possible bugs in Access I think we should take the time to examine the situation.

1.
We should not simply believe anything we see written on the www no mater who writes it. Even super gurus can have a bad day after a night on the Kryptonite. Then along comes some normal guru and repeats it without testing. Before too long we can have folklore propagated by other super gurus, gurus and normal people like us poor sods. The folklore has become a living entity which is vigorously defended by everyone who has helped in its propagation.

2.
If it ever was a bug and if that bug was ever fixed probably doesn’t matter. The point here is that the possible bug would be stable and reproducible. If someone writes something in a non-English version such as Greek and gets Bulgarian string comparisons then they would probably let Microsoft know and, in the mean time, change to Option Compare Text.

The only reason I change it is that I put things in the Sample Database Forum where anyone can download it. I don’t know where it’s going nor under what circumstances it will be running.

3.
Now if we see:-
Option Explicit
Option Compare Text
in a posters code, and that code has a problem, then the most likely reason is that the code was obtained from a VB and not a VBA application. That then should flag a possible difference between the syntax of the two.

4.
So, I really don’t think it matters too much under normal circumstances if the bug has been fixed or not if, in deed, it ever was a bug.


Chris.
 
Hi and thanks for the replies.... Curiously I have found the opposite to that which [I think] I expected... I have set Option Compare Text in my modules and Access has gone case-insensitive... so...

IF "fred"="Fred" THEN

.... is true......

Access... more red herrings then a Swedish trawler!... :)

As for Bulgaria... went skiing there once and it seems very nice!
 
Last edited:
Apologies gray, we meant Binary. I always get it mixed up.
 

Users who are viewing this thread

Back
Top Bottom