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
|
Public Function PeupleTableIndividu()
On Error GoTo MyErr
Const cMaTable As String = "Table", cVide As String = "-"
Dim Db As DAO.Database, RRs As DAO.Recordset, Wrs As DAO.Recordset, s As String, a() As Variant, v As Variant, i As Long
a = Array("IndividuS1", "IndividuS2", "IndividuS3", "IndividuT1", "IndividuT2", "IndividuT3")
Set Db = CurrentDb
Set RRs = Db.OpenRecordset(cMaTable, dbOpenSnapshot)
Set Wrs = Db.OpenRecordset("tIndividu", dbOpenDynaset)
With RRs
While Not .EOF
For Each v In a
If Nz(.Fields(v), cVide) <> cVide Then
s = .Fields(v)
Wrs.FindFirst "Individu=""" & s & """"
If Wrs.NoMatch Then
Wrs.AddNew
Wrs!Individu = s
Wrs.Update
i = i + 1
End If
End If
Next v
.MoveNext
Wend
End With
'Ajoute cas vide (-)
Wrs.AddNew
Wrs!Individu = cVide
Wrs.Update
MsgBox i & " individu(s) unique(s) ajouté(s) à la table tIndividu", vbInformation
fin:
RRs.Close
Wrs.Close
Set RRs = Nothing
Set Wrs = Nothing
Set Db = Nothing
Exit Function
MyErr:
MsgBox "Erreur n°" & Err.Number & vbCrLf & "Description : " & Err.Description, vbCritical, "PeupleTableIndividu()"
Resume fin
End Function |
Partager