Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking Strings 2

Status
Not open for further replies.

gavinjb

Programmer
Apr 24, 2003
106
GB
I have an application where I need to check to see if the two strings are identical, the only problem is that in access the followign would be seen as the same.

"Hello World"
"hello world"
"HELLO WORLD"

does anyone know how to tell Access when comparing strings to check the case as well as the characters.

Thanks,


Gavin,
 
you would probably need to convert to ascii characters

Be ALERT - Your country needs Lerts
 
Hi

In the worst case, you could write a user function (not tested)

Public CaseCompare(str1 as String, str2 as String) as Boolean
dim i as Integer
CaseCompare = True
If len(str1) <> len(str2) Then
CaseCompare = False
End if
for i = 1 to len(str1)
if chr(mid(str1,i,1)) <> chr(Mid(str2,i,1)) Then
CaseCompare = False
i = len(str1) + 1
end if
Next i
End Function


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Made a simple change to your function and it work perfectly thanks,

Public Function CaseCompare(str1 As String, str2 As String) As Boolean
Dim i As Integer
CaseCompare = True
If Len(str1) <> Len(str2) Then
CaseCompare = False
End If
For i = 1 To Len(str1)
If Asc(Mid$(str1, i, 1)) <> Asc(Mid$(str2, i, 1)) Then
CaseCompare = False
i = Len(str1) + 1
End If
Next i
End Function
 
Found the following in the Help section. Is this what you're looking for, a string comparison that checks for case as well.


StrComp
Returns an integer indicating the result of a string comparison. In other words, the function compares one string to another string and returns a value based on the results. The return values are based on one of the conditions indicated in the following table:

Condition Returned Value
string1 is less than string2 — 1
string1 is equal to string2 0
string1 is greater than string2 1
string1 or string2 is Null Null


Syntax: StrComp(string1, string2, compare)

Example
StrComp("ABCD", "abcd", 1) returns the value 0.
StrComp("ABCD", "abcd", 0) returns the value— 1.


**********************************************
Value Constant (for use in VBA code) Description

—1 = vbUseCompareOption
Performs a comparison using the setting of the Option Compare statement. Option Compare statements are used in Microsoft Visual Basic® modules to determine how strings are compared.

0 = vbBinaryCompare
Performs a binary (case-sensitive) comparison.

1 = vbTextCompare
Performs a textual (non-case-sensitive) comparison.

2 = vbDatabaseCompare
Performs a comparison based on information in your database. The comparison is based on the sort order for the locale specified by the regional settings in Microsoft Windows® Control Panel.
**********************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top