Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access VBA find the last occurrent of a string?

Access VBA has Instr to return the position of the first occurrence of a string in another string.

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

Is there any method to return the position of the last occurrence of a string in another string?

like image 716
Nexus Avatar asked Jul 04 '13 02:07

Nexus


People also ask

How do you find the last occurrence of a character in a string?

The strrchr() function finds the last occurrence of c (converted to a character) in string.

What is Instrrev in VBA?

VBA INSTRREV Function, as stands for 'In String Reverse', returns the position of the first occurrence of a search string (substring) in another string, starting from the end of the string (from right to left) from which we are looking for a searchable string.

How to Find a character in a string in ms Access?

The Microsoft Access InStr function returns the position of the first occurrence of a string in another string.

How do you find the last occurrence of a string?

Find the Last Occurrence of a String In Another String. If we want to find whether or not a character or string occurs within another string we can use FIND or SEARCH. But these functions only tell us if a string (or character) exist in another string, they don't tell us if the string we are looking for occurs multiple times.

How to find the last occurrence of a character in Excel?

For the second method, we’re going to use the MATCH function, the SEQUENCE function, the MID function, and the LEN function to find the position of the last occurrence of a character in the string. Remember the SEQUENCE function is only available on Excel 365 or Excel 2021.

How do I get the last V in an access query?

You can also use the InstrRev function in a query in Microsoft Access. This query will return the position of the last "v" in the LastName field. The results will be displayed in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.

How to find the last slash in a string in Excel?

For the first method, we’re going to use the FIND function, the SUBSTITUTE function, the CHAR function, and the LEN function to find the last position of the slash in our string. Firstly, type the following formula in cell D5. Our main function is FIND. We’re going to find the CHAR (134) value in our string. Output: †.


2 Answers

Try InstrRev instead - see here

Note the different syntax to InStr:

InstrRev(stringcheck, stringmatch[, start[, compare]])

like image 186
barrowc Avatar answered Sep 27 '22 19:09

barrowc


Check this link, example code from MS

https://msdn.microsoft.com/en-us/library/t2ekk41a(v=vs.90).aspx

Dim TestString As String = "the quick brown fox jumps over the lazy dog" 
Dim TestNumber As Integer 
' Returns 32.
TestNumber = InStrRev(TestString, "the")
' Returns 1.
TestNumber = InStrRev(TestString, "the", 16)
like image 36
Calum Avatar answered Sep 27 '22 21:09

Calum