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
| Sub ajoutEnregistrement()
Dim Cn As ADODB.Connection
Dim Fichier, Feuille, strSQL As String
Dim leprix As Integer
Dim Nom, Prenom As String
Fichier = "C:\Base.xls"
Feuille = "Feuil1"
'Les données à insérer:
nvDate = CDate("3/05/2012")
Nom = "NomTest"
Prenom = "PrenomTest"
leprix = 40
Set Cn = New ADODB.Connection
With Cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
& Fichier & ";Extended Properties=""Excel 12.0;HDR=Yes;"""
.Open
End With
strSQL = "INSERT INTO [" & Feuille & "$]([LaDate],[leNom],[lePrenom],[PrixUnit]) VALUES ('" & nvDate & "', '" & Nom & "', '" & Prenom & "', '" & leprix & "')"
'strSQL = "INSERT INTO [Feuil1$]([LaDate],[leNom],[lePrenom],[PrixUnit]) VALUES (" & "12/12/12" & ", " & "'" & "test" & "', " & "'" & "test" & "', " & 50 & ")"
',[leNom],[lePrenom],[PrixUnit]
'& "', '" & Nom & "', '" & Prenom & "', '" & leprix
Cn.Execute strSQL
Cn.Close
Set Cn = Nothing
End Sub |
Partager