HomePrivacy PolicyFeedbackLink to usSite Map

MS Access: InstrRev Function


In Access, the InstrRev function returns the position of the first occurrence of a string in another string, starting from the end of the string. This is similar to the Instr function which returns the position of the first occurrence, starting from the beginning of the string.

The syntax for the InstrRev function is:

InstrRev ( string_being_searched, string2 [, start [ , compare] ] )

string_being_searched is the string that will be searched.

string2 is the string to search for.

start is optional. It is the starting position for the search. If this parameter is omitted, the search will begin at position -1 which is the last character position.

compare is optional. This is the type of comparison to perform. The valid choices are:

VBA Constant Value Explanation
vbUseCompareOption -1 Uses option compare
vbBinaryCompare 0 Binary comparison
vbTextCompare 1 Textual comparison
vbDatabaseCompare 2 Comparison based on your database

Note:

If string2 is not found within string_being_searched, the InstrRev function will return 0.

If string_being_searched is zero-length, the InstrRev function will return 0.

If string_being_searched is null, the InstrRev function will return null.

If start is null, the InstrRev function will return #Error.


For example:

InstrRev ("alphabet", "a") would return 5
InstrRev ("alphabet", "a", -1) would return 5
InstrRev ("alphabet", "a", 1) would return 1
InstrRev ("alphabet", "a", 2) would return 1
InstrRev ("alphabet", "a", 3) would return 1
InstrRev ("alphabet", "a", 4) would return 1
InstrRev ("alphabet", "a", 5) would return 5
InstrRev ("alphabet", "a", 6) would return 5
InstrRev ("alphabet", "a", 7) would return 5
InstrRev ("alphabet", "a", 8) would return 5
InstrRev ("alphabet", "a", 9) would return 0

VBA Code

The InstrRev function can be used in VBA code. For example:

Dim LPosition As Integer

LPosition = InstrRev ("alphabet", "a")

In this example, the variable called LPosition would now contain the value 5.


SQL/Queries

You can also use the InstrRev function in a query.


Frequently Asked Questions


Question:  In Access, all values in a column have a file extension suffix. How can I remove the suffix and the "." from all values in this column?

Answer: You can use the InstrRev function to remove a file extension. For example, if we had a column called Filename that contained values as follows:


And we wanted to remove the extension from each Filename, we could use the InstrRev function as follows:

Left([Filename],InStrRev([Filename],".")-1)


This would return the following query results: