Bonjour a tous,
Comme on me l'a conseille, j'essaye d'importer depuis excel des donnees grace a ce code :
'Import data from an excel file for the discounted dates
Function importFromExcelFile2()
Dim ConnectBD As Object
Dim Rs As Object
Dim Cl As Excel.Workbook
Dim Fe As Excel.Worksheet
Dim I As Integer
Dim ExcelPath As String
Dim book As Object
Set Fe = Nothing
Set Cl = Nothing
Set Rs = Nothing
Set ConnectBD = Nothing
DoCmd.RunSQL "Delete * FROM NewDiscountedProduct"
ExcelPath = Application.CurrentProject.Path & "\FD_SPE1.xls"
Set Cl = Excel.Application.Workbooks.Open(ExcelPath)
Set Fe = Cl.Worksheets("Sheet1")
'connexion
Set ConnectBD = CreateObject("ADODB.Connection")
Set ConnectBD = CurrentDb
' Set ConnectBD = CurrentDb
Set Rs = CreateObject("ADODB.Recordset")
Set Rs = ConnectBD.OpenRecordset("SELECT * FROM NewDiscountedProduct")
With Rs
'.CursorType = 1
'.LockType = 3
'.Open "SELECT * FROM NewDiscountedProduct"
'.Open "SELECT * FROM NewDiscountedProduct", ConnectBD
'ajout de plusieurs enregistrements
'situés à partie de la ligne 2 afin d'éviter
'les entêtes de colonnes. A adapter sinon
' For I = 2 To [A65536].End(xlUp).Row
For I = 2 To 28
.AddNew
.Fields("MMITNO") = Fe.Cells(I, 1)
.Fields("MMITDS") = Fe.Cells(I, 2)
'.Fields("MMSPE1") = CDate(Fe.Cells(I, 3))
'.Fields("MMSPE1") = Format(Fe.Cells(I, 3), "dd/mm/yyyy")
'.Fields("MMSPE1") = Format(Temp, "dd/mm/yyyy")
.Fields("MMSPE1") = "#" & Format(Fe.Cells(I, 3), "Short Date") & "#"
.Update
Next I
End With
'ConnectBD.Close
'|---------------------------------------------------------------|
Form_frmProgressBar.IncRefreshComp 5, "Replicating (Excel) Table 10/10"
End Function
J'ai une erreur de type/format sur la ligne :
.Fields("MMSPE1") = Fe.Cells(I, 3)
En effet, mon champ dans Access est de type Date -> dd/mm/yyyy, idem pour le champ MMSPE1 et pourtant cette ligne de code fait planter le code,
Si quelqu un a la solution, plz help me!
Merci