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
| present = False
cnx.Provider = "Microsoft.Jet.Oledb.4.0"
cnx.ConnectionString = "C:\huhu.mdb"
cnx.Open
If Me.lst_nomFourn.Value <> "" Then
Fourn = Me.lst_nomFourn.Value
SQL = "SELECT nom_fournisseur FROM Fournisseur;"
rst.Open SQL, cnx
If Not rst.EOF Then 'si la table n'est pas vide
'Parcourons le recordset
rst.MoveFirst
Do While Not (rst.EOF)
If rst("nom_fournisseur") = Fourn Then
MsgBox ("Le fournisseur est déjà référencé.")
present = True
Exit Do
End If
rst.MoveNext
Loop
If Not present Then
'On ajoute : INSERT INTO
SQL = "INSERT INTO fournisseur (nom_fournisseur) VALUES (""" & Fourn & """);"
rst.Open SQL, cnx
End If
Else
'Premier ajout
SQL = "INSERT INTO fournisseur (nom_fournisseur) VALUES (""" & Fourn & """);"
rst.Open SQL, cnx
End If
End If
rst.Close |
Partager