Case Sensitive String Comparisons

G

Guest

I am am trying to automatically correct the case of strings entered into a
form. Pseudocode:

if me!name = lcase(me!name) then
me!name = propercase (me!name)
end if

Simple sounding, I know. But I can't get the strings to do a case-sensitive
comparison. According to VB, "a" = "A" is true. Any ideas?

Thanks!

Nick
 
S

SusanV

I'm curious as to why you feel you need to only run a "correction" procedure
when simply using me!name = propercase(me!name) would ensure that all
entries are set to proper. The comparison (if/when you get it working) will
take more processing than simply running the propercase function...
 
W

Wayne Morgan

First, you don't say exactly what you're trying to accomplish. See if the
function StrConv() using the vbProperCase argument will do what you want. If
so, you don't need to do the binary comparison.

To do a binary compare, the StrComp() function has that option.
 
G

Guest

Haha, well yeah, I guess my question would raise a few eyebrows. It's just
that some names are correct without proper case, such as OConnell or
McCallister or whatever it may be. I figure that if someone types in a name
that contains at least one capital letter, they probably got it right. But
if someone types in a name that is all lowercase, they probably got it wrong.
Thus, I would like to auto-correct only the names that are entered in as
lower case.

As to why this is even important in a database... I am writing this database
for a department that is responsible for sending out mailings to guests that
are coming to their resort. Appearances are everything in the tourism
industry, and since the database is being used in mailings, I would like to
try to get everything... anal-retentively perfect. For lack of a better
term. :)

Nick
 
W

Wayne Morgan

A couple of other options.

1) Change the Option Compare statement at the top of the module to Option
Compare Binary.

2) Use the Asc() function to compare the characters.

Example (from debug window):
?Asc("A") <> Asc("a")
True
 
S

SusanV

Makes sense now - thanks for the explanation!

Tatakau said:
Haha, well yeah, I guess my question would raise a few eyebrows. It's
just
that some names are correct without proper case, such as OConnell or
McCallister or whatever it may be. I figure that if someone types in a
name
that contains at least one capital letter, they probably got it right.
But
if someone types in a name that is all lowercase, they probably got it
wrong.
Thus, I would like to auto-correct only the names that are entered in as
lower case.

As to why this is even important in a database... I am writing this
database
for a department that is responsible for sending out mailings to guests
that
are coming to their resort. Appearances are everything in the tourism
industry, and since the database is being used in mailings, I would like
to
try to get everything... anal-retentively perfect. For lack of a better
term. :)

Nick
 
G

Guest

The Asc function seems to have done the trick! Though it only checks the
first character of a string... and I am reluctant to change the comparisons
for the entire form to Binary, because I really don't know how that would
affect the entire database (there is a LOT of code in there)...

ah well. I'll just hope that no one comes around with a last name that
starts with a lowercase letter!

Thanks!

Nick
 
D

Douglas J Steele

If StrComp(Me!name, LCase(Me!name), vbBinaryCompare) <> 0 Then
Me!name = StrConv(Me!name, vbProperCase)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top