1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| Option Compare Database
Public Sub Commande12B_Click()
'Procédure de dédoublonnage qui compare chaque champ sur Raison sociale, Ville, CP, adresse
Dim MaBd As Database
Dim MyRst As Recordset
Dim DptOk As String
Dim Nb_Enr As Long, x As Long, l As Long, k As Long
Dim Valeur As String, CurEnrg1 As Variant, CurEnrg2 As Variant, LIBAD As String, DP As String, Valvil As String, Str As String, VAL As Integer
Set MaBd = CurrentDb
Set tb = MaBd.TableDefs!sd
Set fi = tb.CreateField("Flag1", dbLong)
Set fi = tb.CreateField("Flag", dbText)
Set fi = tb.CreateField("Flag3", dbLong)
With tb
.Fields.Append .CreateField("Flag1", dbLong)
.Fields.Append .CreateField("Flag", dbText)
.Fields.Append .CreateField("Flag3", dbLong)
End With
Set MyRst = MaBd.OpenRecordset("sd", dbOpenDynaset)
If MyRst.Bookmarkable Then
MyRst.MoveLast
Nb_Enr = MyRst.RecordCount
MyRst.MoveFirst
For x = 1 To Nb_Enr - 1
CurEnrg1 = MyRst.Bookmark
' rs = Raison sociale
If Not IsNull(MyRst!rs) Then
Valeur = MyRst!rs
End If
If Not IsNull(MyRst!LIBADR) Then
LIBAD = Right(MyRst!LIBADR, 5)
End If
'ACHEM = Ville
If Not IsNull(MyRst!ACHEM) Then
Valvil = Left(MyRst!ACHEM, 5)
End If
'CDPOS : Code postal
If Not IsNull(MyRst!CDPOS) Then
DP = Left(MyRst!CDPOS, 3)
End If
MyRst.MoveNext
'Je rentre dans la boucle qui compare chaque champ à la totalité des autres champs de la base
'Sur les 3 premiers caractères Code Postal, 5 derniers caractères ville, et début position + fin de position Raison sociale
Do
k = Round((Len(MyRst!rs) * 0.66), 0)
l = Round((Len(Valeur) * 0.66), 0)
If DP = Left(MyRst!CDPOS, 3) And Valvil = Left(MyRst!ACHEM, 5) And LIBAD = Right(MyRst!LIBADR, 5) And _
(Left(MyRst!rs, 4) = Left(Valeur, 4) Or Right(MyRst!rs, l) = Right(Valeur, k)) Then
If IsNull(MyRst!Flag1) Then
CurEnrg2 = MyRst.Bookmark
MyRst.Edit
MyRst!Flag1 = x
MyRst!Flag = "N"
MyRst!Flag3 = k
MyRst.Update
MyRst.Bookmark = CurEnrg1
MyRst.Edit
MyRst!Flag1 = x
MyRst.Update
MyRst.Bookmark = CurEnrg2
End If
End If
MyRst.MoveNext
Loop Until MyRst.EOF
MyRst.MoveFirst
MyRst.Move x
Next x
End If
MyRst.Close
End Sub |
Partager