I am having trouble coming up with a good search to find simular customer names within my database. A friend of mine suggested the code in red but it is really not doing what I need it to.
I could have customer names that vary so I need it to match names like the example below.
Lets say I have these names in my master table
Advanced Communication Systems Inc
Advnaced Communication sys
Advanced Communications
I have a new name which is Advanced Comm the code below would not find any of the above names unless I put the % very high. The downside of moving the % higher is the number of names that are not even close to Advanced Communications will be listed
Does anyone have a better way to do comparisons to find like names?
I could have customer names that vary so I need it to match names like the example below.
Lets say I have these names in my master table
Advanced Communication Systems Inc
Advnaced Communication sys
Advanced Communications
I have a new name which is Advanced Comm the code below would not find any of the above names unless I put the % very high. The downside of moving the % higher is the number of names that are not even close to Advanced Communications will be listed
Does anyone have a better way to do comparisons to find like names?
Code:
...
...
Set ctl = frm!lstNewPaNames
...
...
For Each varItm In ctl.ItemsSelected
For intI = 0 To ctl.ColumnCount - 1
'find names with the best matches
Do While Not rsMaster.EOF
If IsNull(rsMaster![paCustName]) Then
Exit Do
End If
[COLOR=red]
intMatches = LD(rsMaster![paCustName], ctl.Column
(intI, varItm))
'At this point intMatches = the number of changes
required to make this string match the other strings
MatchPercent = (intMatches / Len(ctl.Column
(intI, varItm))) * 100
'If we matched more than a certain percent of the
characters then add it to the matched table
If MatchPercent < 40 Then
[/color]
With rsMatch
.AddNew
.Fields("matchAxisID") = rsMaster![paAxisID]
.Fields("matchDataCentID") = rsMaster![paDataAccessID]
.Fields("matchPaName") = rsMaster![paCustName]
.Fields("matchPaDesignation") = rsMaster![paDesignation]
.Fields("matchDiscount") = rsMaster![pa05Discount]
.Update
End With
End If
rsMaster.MoveNext
Loop
'Refresh the form so the list box gets it's new data
Me.Refresh
Next intI
Next varItm