InStr
Using the InStr Function
In this tutorial you will learn how to use the InStr Function.
The InStr function returns the position of the first occurrence of a string in another string.
=Instr ( [start], searchin, searchfor, [compare] )
start is optional. It is the starting position for the search. If this parameter is omitted, the search will begin at position 1.
searchin is the string that will be searched.
searchfor is the string to search for.
compare is optional. This is the type of comparison to perform.
In this example we will use a given sentance: "Hello, My name is"
The result is 2.
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 | InStr Returns |
searchin is zero-length | 0 |
searchin is Null | Null |
searchfor is zero-length | start |
searchfor is Null | Null |
searchfor is not found | 0 |
searchfor is found within searchin | Position at which match is found |
start > Len(searchfor) | 0 |
FORM
In a Form you could set the Default Value of a Textbox to
=InStr("Hello, My name is", "e")
VBA
In a Form add a TEXTBOX control and rename it "txtInStr", then you could add the following in the Load Event.
Private Sub Form_Load()
txtInStr = InStr("Hello, My name is", "e")
End Sub
Course(s)
Access Expert 14
|
Access Expert 19
Access 222
|
Access 308
Seminars
Access Email
|
Access Search
|
Access SQL 2
|
Access Web Sync
Tips
See this FREE Tip on InStr.
Search
You can find more about this by searching the website.
By: Alex Hedley
Click here to sign up for more FREE tips
|