Ucase issue (1 Viewer)

kirkm

Registered User.
Local time
Today, 14:14
Joined
Oct 30, 2008
Messages
1,257
The following fails in Access
Code:
If (strIn = UCase(strIn) Then
    'It Is U.C.
 Else
    It is NOT U.C.
End If
I suspect because of Option Compare Database. Is there any way to make the code work as intended?
 

plog

Banishment Pending
Local time
Yesterday, 21:14
Joined
May 11, 2011
Messages
11,646
1. That's not good code for a lot of reasons--mostly because you don't have code there and a few syntax reasons.
2. What are your intentions?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:14
Joined
Oct 29, 2018
Messages
21,473
Check out the StrComp() function.
 

kirkm

Registered User.
Local time
Today, 14:14
Joined
Oct 30, 2008
Messages
1,257
I've been checking out StrComp for 2 days! That's why I asked here.
My intention (this example was on Google) is to know why that fails and how best to have it work.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:14
Joined
Oct 29, 2018
Messages
21,473
I've been checking out StrComp for 2 days! That's why I asked here.
My intention (this example was on Google) is to know why that fails and how best to have it work.
Hi. If you're goal is to have case sensitivity, then that code did not fail, because VBA is not case sensitive.

To test that, try the following in the Immediate Window.

Code:
?"test"="TEST"
 

plog

Banishment Pending
Local time
Yesterday, 21:14
Joined
May 11, 2011
Messages
11,646
I figured your intentions involved "have it work". I, like the computer, do not know what that means specifically. What do you want to actually occur in the two cases?
 

kirkm

Registered User.
Local time
Today, 14:14
Joined
Oct 30, 2008
Messages
1,257
? "test"= "TEST" returns True in Access but False in Excel. Both are vba.
To use Option Compare Binary I think has to be Global, but I'm not sure if global to the whole DB or just current module. This may well upset something else if changed.
? strcomp("test", "TEST",vbBinaryCompare) = 1
Is that the solution? 1 being false?
Does strcomp use all of both strings in its calculation ?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:14
Joined
Oct 29, 2018
Messages
21,473
? "test"= "TEST" returns True in Access but False in Excel. Both are vba.
To use Option Compare Binary I think has to be Global, but I'm not sure if global to the whole DB or just current module. This may well upset something else if changed.
? strcomp("test", "TEST",vbBinaryCompare) = 1
Is that the solution? 1 being false?
Does strcomp use all of both strings in its calculation ?
Hi. StrComp() compares the two String arguments, and it's what I'd recommend you use if you want to dictate how you want the comparison to be performed.
 

kirkm

Registered User.
Local time
Today, 14:14
Joined
Oct 30, 2008
Messages
1,257
Right. In trying to sort his I had a situation where StrComp was failing, but I can't duplicate it again. And looking at some explanations where A=AA or A< AA was just plain gibberish to me! Nowhere did it say Binary detects the casing. Anyway, it all seems OK now. Many thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:14
Joined
Oct 29, 2018
Messages
21,473
Right. In trying to sort his I had a situation where StrComp was failing, but I can't duplicate it again. And looking at some explanations where A=AA or A< AA was just plain gibberish to me! Nowhere did it say Binary detects the casing. Anyway, it all seems OK now. Many thanks.
Good luck!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:14
Joined
May 7, 2009
Messages
19,242
Option declaration is not Global.
It is Module-wise, meaning the effect is Only on That Module.
if you did not declare it on the Module, the Default is Option Compare Binary.
 

kirkm

Registered User.
Local time
Today, 14:14
Joined
Oct 30, 2008
Messages
1,257
Thanks arnelgp that's good to know.
 

Users who are viewing this thread

Top Bottom