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 89 90 91 92 93 94
| Private Sub Copier_Click()
Dim db As DAO.Database
Dim MaTable As Recordset
Dim Cherche As Recordset
Dim j As Integer
'Les variables suivantes sont les champs de ma table "enregistrements" en y incluant DateJ
Dim N As Integer
Dim Duree As Integer
Dim NMAT As Integer
Dim NCHAUFF As Integer
Dim Chantier As String
Dim Chef As Integer
Dim Interim As Integer
Dim Loc As Integer
Dim Typeloc As String
Dim Indic As String
If IsNull(Me!DateD) Or Me!DateD = "" Then
Exit Sub
End If
Set MaTable = CurrentDb.OpenRecordset("Enregistrements", dbOpenDynaset)
Set Cherche = CurrentDb.OpenRecordset("Enregistrements", dbOpenDynaset)
j = DCount("[DateJ]", "Enregistrements", "[DateJ] = #" & Format(Me.Jour, "mm/dd/yyyy") & "# AND [Chef] =" & Me.Chef & " AND [N°]=" & Me.N°)
MsgBox (j & " enregistrement(s) ont été détectés !")
MaTable.FindFirst "[DateJ] = #" & Format(Me.Jour, "mm/dd/yyyy") & "# AND [Chef] =" & Me.Chef & " AND [N°]=" & Me.N°
While (Not MaTable.NoMatch)
N = Me.N°
Duree = Nz(MaTable("Durée"), 0) 'Les recordset n'aiment pas vraiment le null
NMAT = Nz(MaTable("NMAT"), 0)
NCHAUFF = Nz(MaTable("NCHAUFF"), 0)
Chantier = Nz(MaTable("Chantier"), "")
Chef = Me.Chef
Interim = Nz(MaTable("Interim"), 0)
Loc = Nz(MaTable("Loc"), 0)
Typeloc = Nz(MaTable("Type loc"), "")
Indic = Nz(MaTable("Indications"), "")
'Toujours dans la table enregistrements, je vérifie à l'aide d'un autre RecordSet "Cherche" si l'enregistrement sur lequel est placé "MaTable" n'existe pas déjà à la Date de destination
Cherche.FindFirst "[DateJ] = #" & Format(Me.DateD, "mm/dd/yyyy") & "# AND [Chef] =" & Chef & " AND [N°]=" & N & " AND [NMAT] =" & NMAT & " AND [NCHAUFF] =" & NCHAUFF & " AND [Interim]=" & Interim & " And [Loc]=" & Loc & " And [Type loc]='" & Typeloc & "'"
If Not Cherche.NoMatch Then
j = j - 1
Else
MaTable.AddNew
MaTable("DateJ") = Me.DateD
If N <> 0 Then 'Ces conditions servent à contourner l'erreur en cas de null
MaTable("N°") = N
End If
If Duree <> 0 Then
MaTable("Durée") = Duree
End If
If NMAT <> 0 Then
MaTable("NMAT") = NMAT
End If
If NCHAUFF <> 0 Then
MaTable("NCHAUFF") = NCHAUFF
End If
If Chantier <> "" Then
MaTable("Chantier") = Chantier
End If
If Chef <> 0 Then
MaTable("Chef") = Chef
End If
If Interim <> 0 Then
MaTable("Interim") = Interim
End If
If Loc <> 0 Then
MaTable("Loc") = Loc
End If
If Typeloc <> "" Then
MaTable("Type loc") = Typeloc
End If
If Indic <> "" Then
MaTable("Indications") = Indic
End If
MaTable("Confirmation") = False
MaTable.Update
End If
MaTable.FindNext "[DateJ] = #" & Format(Me.Jour, "mm/dd/yyyy") & "# AND [Chef] =" & Me.Chef & " AND [N°]=" & Me.N°
Wend
MsgBox (j & " enregistrement(s) ont été copiés.")
Cherche.Close
MaTable.Close
End Sub |
Partager