G
Guest
Hi
I'd like to know if there is something similar to Sql Server function
soundex() in Access ?
I'd like to know if there is something similar to Sql Server function
soundex() in Access ?
A SoundEx function converts a string to a number, with the premise that two
numbers close together are derived from strings that sound alike. Access
does not have a built-in function to do this, unlike SQL Server.
Function Soundex (ByVal S As String) As String
S = UCase$(Trim$(S))
Dim Code As Integer: Code = 0
Dim Last As Integer: Last = 0
Dim R As String: R = ""
Dim i As Long: For i = 1 To Len(S)
Select Case Mid$(S, i, 1)
Case "B", "F", "P", "V"
Code = 1
Case "C", "G", "J", "K", "Q", "S", "X", "Z"
Code = 2
Case "D", "T"
Code = 3
Case "L"
Code = 4
Case "M", "N"
Code = 5
Case "R"
Code = 6
Case Else
Code = 0
End Select
If (i = 1) Then
R = Mid$(S, 1, 1)
ElseIf (Code <> 0 And Code <> Last) Then
R = R & Code
End If
Last = Code
Next i
Soundex = Mid$(R & "0000", 1, 4)
End Function