Le code ne marche pas et je reçois ce message d'erreur: "Compile error: Argument not optional"
Bonjour à tous,
comme indiqué dans le titre ci-dessus, je n'arrive pas à definer le problem auquel je suis confronté:
Voici mon code, il est censé parametrer l'importation de données depuis MS Excel 2010.
Code:
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
| Private Sub cmdImportR_Click()
On Error GoTo err_import
MyFile = "\\soa-msb-fs\Rations Invoice & Budget\Database\Ration.xlsx"
Set Mysh = MyFile.LaRequisition
Set tb = [Commande Client]
Call Importdata
err_import:
MsgBox Err.Description
Resume Next
End Sub
Public Function Importdata(MyFile As Excel.Workbook, Mysh As Excel.Worksheet, tb As Table)
On Error GoTo err_import
'Dim MyFile As New Excel.Application
'Dim tb As New Table
'Dim MaPlage As Excel.Range
'Set Mysh = MyFile.Worksheet
DoCmd.TransferSpreadsheet acImport, , tb, MyFile.Mysh, True
err_import:
MsgBox Err.Description
Resume Next
End Function |
NB. Je ne suis pas trop confortable en VBA.
Nouveau message d'erreur apres quelques modifications du code
Le nouveau message qui s'affiche est maintenant: Object Variable or With block variable not set
après que j'ai modifié le code comme suite:
Code:
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
| Private Sub cmdImportR_Click()
On Error GoTo err_import
Dim db As DAO.Database
Dim MaTable As DAO.Recordset
Dim MonFichier As Excel.Workbook
Dim MaFeuille As Excel.Worksheet
Set db = CurrentDb
MonFichier = "\\soa-msb-fs\Rations Invoice '&' Budget\Database\Ration.xls"
MaFeuille = MonFichier.LaRequisition
Set MaTable = db.OpenRecordset("Commande Client")
Call Importdata(MonFichier, MaFeuille, MaTable)
err_import:
'MsgBox Err.Description
Resume Next
End Sub
Public Function Importdata(MyFile As Excel.Workbook, Mysh As Excel.Worksheet, tb As Table)
On Error GoTo err_import
'Dim MyFile As New Excel.Application
'Dim tb As New Table
'Dim MaPlage As Excel.Range
'Set Mysh = MyFile.Worksheet
DoCmd.TransferSpreadsheet acImport, , tb, MyFile.Mysh, True
err_import:
MsgBox Err.Description
Resume Next
End Function |