Access VBA custom Function to count substring in string


Thu Jul 28 2022 10:54:03 GMT+0000 (Coordinated Universal Time)

Saved by @paulbarry

Public Function wCountSubStr(str As String, substr As String) As Integer
    lenstr = Len(str)
    lensubstr = Len(substr)
    For i = 1 To lenstr
        tempString = Mid(str, i, lensubstr)
        If tempString = substr Then
            count = count + 1
        End If
    Next i
    wCountSubStr = count
End Function