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
|
Private Sub TestDates()
Dim ConnexionDonnees As ADODB.Connection 'Connexion au classeur des données
Dim Enregistrements As ADODB.Recordset
Dim Commande As ADODB.Command
Dim Requete As String
Dim FichierDonnees As String
'On récupère le chemin du classeur
FichierDonnees = ThisWorkbook.Path & "\Comptes Familiaux - Donnees.xlsx"
'On ouvre la connexion aux données
Set ConnexionDonnees = New ADODB.Connection
With ConnexionDonnees
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
& FichierDonnees & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;ReadOnly=False;"""
.Open
End With
Requete = "INSERT INTO [Ecritures$] (Date) VALUES (#12/31/2020#)"
Set Commande = New ADODB.Command
Set Enregistrements = New ADODB.Recordset
Enregistrements.CursorType = adOpenDynamic
Enregistrements.LockType = adLockOptimistic
With Commande
.ActiveConnection = ConnexionDonnees
.CommandType = adCmdText
.CommandText = Requete
.Execute
End With
Set Commande = Nothing
Set Enregistrements = Nothing
End Sub |