Nexus
Nexus

Reputation: 821

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?

Upvotes: 13

Views: 27478

Answers (2)

Calum
Calum

Reputation: 104

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)

Upvotes: 4

barrowc
barrowc

Reputation: 10679

Try InstrRev instead - see here

Note the different syntax to InStr:

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

Upvotes: 19

Related Questions