Thank you all for posting this. It has been a tremendous help. I especially found Billy's code useful. I do, however, want to pose a question. In Billy's code, you can compare two fields and you have to select how many characters to match. Is there any way to modify the code so you don't have to select the number of characters to match but instead it displays the longest number of characters and the percentage (and if possible the second longest number of characters and the percentage of match).
Example Current code
Serrano,N ^
Serrano,Noel
R, John ^
R MD, John
John,Brent ^
John,B Trent
Chicago,IL ^
Chicago, Illinois
680 N LakeShore Dr ^
680 Lake Shore
60611-2314 ^ 60611
342-55-2035 ^ 342662035
312-555-1212 ^ 3125551212
123 Main St ^ 123 1st Ave
Billy's Code (current using 4 characters to match)
John,Brent ^
John,B Tront ^
Yes! John
342-55-2035 ^
342662035 ^
Yes! 2035
R, John ^
R MD, John ^
Yes! , Jo
Chicago,IL ^ Chicago, Illinois ^
Yes! Chic
312-555-1212 ^ 3125551212 ^
Yes! 1212
60611-2314 ^ 60611 ^
Yes! 6061
Serrano,N ^ Serrano,Noel ^
Yes! Serr
680 N LakeShore Dr ^ 680 Lake Shore ^
Yes! 680
123 Main St ^ 123 1st Ave ^
Yes! 123
Desired Output
FieldA ^ FieldB ^
Matches ^
Percent (match / longest field) ^
2nd largest match ^ Percent (match / longest field) ^
Total percentage match ^
Did not match (excludes matches) ^
Percentage not match
John,Brent ^ John,B Tront ^"John,B"^50.0%^"nt"^16.7%^66.7%^" Tro"^33.3%
342-55-2035^342662035^"2035"^36.4%^"342"^27.3%^63.6%^"-55-"^
36.4%
R, John^R MD, John^", John"^60.0%^"R"^10.0%^70.0%^" MD"^30.0%
Chicago,IL^Chicago, Illinois^"Chicago,"^47.1%^"Il"^11.8%^58.8%^"linois" & " "^41.2%
312-555-1212^3125551212^"1212"^33.3%^"312" & "555"^50.0%^83.3%^"-" & "-"^16.7%
60611-23146^60611^"60611"^50.0%^NULL^0.0%^50.0%^"-2314"^50.0%
Serrano,N^Serrano,Noel^"Serrano,N"^75.0%^NULL^0.0%^75.0%^"oel"^25.0%
680 N LakeShore Dr^680 Lake Shore^"Shore "^33.3%^" Lake"^27.8%^61.1%^"N" & "Dr"^16.7%
123 Main St^123 1st Ave^"123 "^36.4%^NULL^0.0%^36.4%^"1st Ave"^63.6%
Original Code from Billy:
Option Compare Database
Public Function TestCharMatch(NbrOfChars, StrSearch As String, strFind As String) As String
'Walks through strFind, NbrofChars at at time, and searches strSearch for a match.
If NbrOfChars > Len(strFind) Then
TestCharMatch = "ERROR!"
Exit Function
End If
Dim Pos As Integer
Pos = 1
Do While Pos <= (Len(strFind) - (NbrOfChars - 1))
If InStr(StrSearch, Mid(strFind, Pos, NbrOfChars)) > 0 Then
TestCharMatch = "Yes! " & Mid(strFind, Pos, NbrOfChars)
Exit Do
Else
TestCharMatch = "Sorry no match!"
End If
Pos = Pos + 1
Loop
End Function
Any help will be greatly appreciated
Noel