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
| Private Sub ajouter_Click()
On Error GoTo err
'déclaration des variables
Dim maBase As DAO.Database
Dim ContactTest As DAO.Recordset
Dim Contact As DAO.Recordset
Set maBase = CurrentDb
Set Contact = maBase.OpenRecordset("Select * from contacts", dbOpenDynaset)
Set ContactTest = maBase.OpenRecordset("select * from [contacts] where [Nom] = '" & Nom & "' and [Prenom] = '" & Prenom & "'", dbOpenDynaset)
If ((ContactTest.RecordCount = 0)) Then
With Contact
.AddNew
!Nom = Me.Nom
!Prenom = Me.Prenom
!Adresse = Me.Adresse
!Cp = Me.Cp
!Ville = Me.Ville
!Pays = Me.Pays
!Jour = Me.Jour
!Mois = Me.Mois
!Annee = Me.Annee
!Tel = Me.Tel
!Mail = Me.Mail
!Commentaires = Me.Commentaires
.Update
End With
Else
MsgBox ("le contact portant ce nom et ce prenom existe déjà")
End If
ContactTest.Close
Contact.Close
DoCmd.Close
[Form_Formulaire1].Refresh
err:
End Sub |
Partager