<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx</link><description>Today’s guest blogger is Michael Groh, co-author of the popular Access 2007 Bible . The VBA language is not, by default, case-sensitive. A statement such as &amp;#160; CBool(&amp;quot;XYZ&amp;quot; = &amp;quot;xyz&amp;quot;) will always return True. You might come across</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx#9805957</link><pubDate>Fri, 26 Jun 2009 23:53:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9805957</guid><dc:creator>Thom Rose</dc:creator><description>&lt;p&gt;Of course, doing just that does not tell you the two strings are the same. &amp;nbsp;It only tells you if strTwo is contained in strOne. &amp;nbsp;For example, if strTwo is &amp;quot;Thom&amp;quot; and strOne is &amp;quot;Thom Rose&amp;quot;, CBool(InStrB(strOne, strTwo)) &amp;nbsp;returns true. &amp;nbsp;To find out if the strings are equal, the line should read:&lt;/p&gt;
&lt;p&gt; If CBool(InStrB(strOne, strTwo)) And CBool(InStrB(strTwo, strOne)) Then...&lt;/p&gt;
</description></item><item><title>re: Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx#9806028</link><pubDate>Sat, 27 Jun 2009 00:50:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806028</guid><dc:creator>Banana</dc:creator><description>&lt;p&gt;Actually, one would use StrComp(strOne, strTwo, vbCompareBinary) which would return 0 if both strings are equal, -1 or 1 when either string are different and the case is sensitive.&lt;/p&gt;
&lt;p&gt;That said, there is an interesting problem- we can easily solve the case sensitivity but not as easily the accent sensitivity.&lt;/p&gt;
&lt;p&gt;Consider the comparison:&lt;/p&gt;
&lt;p&gt;&amp;quot;Mueller&amp;quot; = &amp;quot;M&amp;#252;ller&amp;quot;&lt;/p&gt;
&lt;p&gt;In the default &amp;quot;General Sort Order&amp;quot; collation of a .mdb file, the comparison is false. However, if we create a new database using German Phonebook collation the comparison now evaluates to true. How would one achieve this comparison in a function short of putting the strings in a brand new database with the collation accordingly set?&lt;/p&gt;
</description></item><item><title>re: Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx#9806069</link><pubDate>Sat, 27 Jun 2009 01:57:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806069</guid><dc:creator>tolmarc</dc:creator><description>&lt;p&gt;Thanks for the tip.&lt;/p&gt;
&lt;p&gt;by the way, could the Access team will share a bit more on the future of VBA in the 2010 version? will it be based on VB.net?&lt;/p&gt;
</description></item><item><title>re: Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx#9806124</link><pubDate>Sat, 27 Jun 2009 03:06:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806124</guid><dc:creator>Clint Covington</dc:creator><description>&lt;p&gt;tolmarc,&lt;/p&gt;
&lt;p&gt;Sorry but we aren't talking about 2010 yet. &lt;/p&gt;
</description></item><item><title>re: Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx#9806417</link><pubDate>Sat, 27 Jun 2009 10:42:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806417</guid><dc:creator>Wayne Phillips</dc:creator><description>&lt;p&gt;Don't forget you can also put Option Compare Binary at the top of your code modules which then changes the way strings are compared inside those modules.&lt;/p&gt;
&lt;p&gt;Then, CBool(&amp;quot;XYZ&amp;quot; = &amp;quot;xyz&amp;quot;) would evaluate to false.&lt;/p&gt;
&lt;p&gt;However, I would usually use the StrComp method (as Banana suggests above) since it's more obvious that you are specifically comparing with case sensitivity.&lt;/p&gt;
</description></item><item><title>re: Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx#9806646</link><pubDate>Sat, 27 Jun 2009 18:37:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806646</guid><dc:creator>Wayne Phillips</dc:creator><description>&lt;p&gt;@Banana...&lt;/p&gt;
&lt;p&gt;There is an undocumented feature of the StrComp function that may be useful in that scenario...&lt;/p&gt;
&lt;p&gt;You can pass a locale ID as the third parameter to the StrComp function. &amp;nbsp;So if we know that the German phonebook LCID has the constant value &amp;amp;H10407, we can just do this:&lt;/p&gt;
&lt;p&gt;Const LOCALE_GERMAN_PHONEBOOK As Long = &amp;amp;H10407&lt;/p&gt;
&lt;p&gt;StrComp(&amp;quot;Mueller&amp;quot;, &amp;quot;M&amp;#252;ller&amp;quot;, LOCALE_GERMAN_PHONEBOOK)&lt;/p&gt;
&lt;p&gt;... which should return 0 (i.e. equal).&lt;/p&gt;
&lt;p&gt;Unfortunately, in passing an LCID to StrComp means that the comparison is always case insensitive. &amp;nbsp;If you need a case sensitive version when specifying a specific LCID, you'll need to use the CompareString API instead.&lt;/p&gt;
</description></item><item><title>re: Case-Sensitive string comparisons</title><link>http://blogs.msdn.com/access/archive/2009/06/26/case-sensitive-string-comparisons.aspx#9806769</link><pubDate>Sun, 28 Jun 2009 00:12:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806769</guid><dc:creator>Banana</dc:creator><description>&lt;p&gt;Wayne,&lt;/p&gt;
&lt;p&gt;Very handy! Thanks for the tip.&lt;/p&gt;
&lt;p&gt;WRT the InStrB, I think a note should be made that it may be comparing at the binary level, not at character, which can be confusing.&lt;/p&gt;
&lt;p&gt;Consider the statement:&lt;/p&gt;
&lt;p&gt;?InStrB(&amp;quot;foobar fooBar&amp;quot;,&amp;quot;bar&amp;quot;)&lt;/p&gt;
&lt;p&gt;21&lt;/p&gt;
&lt;p&gt;?InStrB(&amp;quot;foobar fooBar&amp;quot;,&amp;quot;bar&amp;quot;)&lt;/p&gt;
&lt;p&gt; 7 &lt;/p&gt;
&lt;p&gt;?Len(&amp;quot;foobar fooBar&amp;quot;)&lt;/p&gt;
&lt;p&gt; 13 &lt;/p&gt;
&lt;p&gt;Contrast this to InStr with comparison specified:&lt;/p&gt;
&lt;p&gt;?InStr(1,&amp;quot;foobar fooBar&amp;quot;, &amp;quot;Bar&amp;quot;,vbTextCompare)&lt;/p&gt;
&lt;p&gt; 4 &lt;/p&gt;
&lt;p&gt;?InStr(1,&amp;quot;foobar fooBar&amp;quot;, &amp;quot;Bar&amp;quot;,vbBinaryCompare)&lt;/p&gt;
&lt;p&gt; 11 &lt;/p&gt;
&lt;p&gt;If we recall that the Access by default uses ucs2 (I think?) so each character are always two bytes wide, so a letter &amp;quot;A&amp;quot; is represented in this binary form:&lt;/p&gt;
&lt;p&gt;00000000 01000001&lt;/p&gt;
&lt;p&gt;When we did the InStrB, it's counting each bytes, not characters and returns the return where the starting byte of the set matches the input. Hence, the result of 21 and 7 in above InStrB represented the actual byte position while InStr using Binary comparsion (e.g. the set of characters as a group of bytes must match exactly the input's group of bytes, rather than merely comparing each byte against each byte)&lt;/p&gt;
&lt;p&gt;(Note this is mostly guesswork based on my limited understanding of how characters &amp;amp; bytes are compared so if I'm incorrect, feel free to correct.)&lt;/p&gt;
</description></item></channel></rss>