StrComp
Using the STRCOMP Function
In this tutorial you will learn how to use the StrComp Function.
The StrComp function returns an Integer indicating the result of a string comparison.
=StrComp( String1, String2, [Compare] )
String1 any valid string
String2 any valid string
Compare [Optional] the type of string comparison
In this example we will compare "Joe" with "joe".
Since case is irrelevant then the result is 0.
The Settings are:
Compare
| Constant | Value | Description |
| vbUseCompareOption | -1 | Performs a comparison using the setting of the Option Compare statement. |
| vbBinaryCompare | 0 | Performs a binary comparison. |
| vbTextCompare | 1 | Performs a textual comparison. |
| vbDatabaseCompare | 2 | Performs a comparison based on information in your database. (Microsoft Office Access 2007 only.) |
The Return Values:
Return Values
| If | StrComp Returns |
| string1 is less than string2 | -1 |
| string1 is equal to string2 | 0 |
| string1 is greater than string2 | 1 |
| string1 or string2 is Null | Null |
Alpha Numerically (Numbers < Letters) [See ASCII codes]
Query
The results using a Query would be
SELECT STRCOMP("Joe", "joe") AS [MyComp]
FORM
In a Form you could set the Default Value of a Textbox to
=STRCOMP("Joe", "joe")
VBA
In a Form add a TEXTBOX control and rename it "txtStrComp", then you could add the following in the Load Event.
Private Sub Form_Load()
txtSTRCOMP = STRCOMP("Joe", "joe")
End Sub
Courses
Access Expert 25
Search
You can find more about this by searching the website.
By: Alex Hedley
Click here to sign up for more FREE tips
|