J'aimerais importer plusieurs fichiers textes (extension .EDI) d'un même dossier dans une table access, j'ai écris ce bout de code pour l'instant mais j'ai toujours l'erreur 35519 "Vous ne pouvez pas importer ce fichier".
La MsgBox m'indique pourtant bien le bon fichier avec le bon chemin...
Voici mon code :
- Code: Tout sélectionner
Private Sub Commande1_Click()
Dim InputDir, ImportFile As String, tblName As String, FileCount As Integer
FileCount = 0
InputDir = "C:EDI"
ImportFile = Dir(InputDir & "*.EDI")
If ImportFile = "" Then
MsgBox ("Aucun fichier EDI n'a été trouvé dans le répertoire suivant : " & vbNewLine & InputDir)
Else
Do While ImportFile <> ""
FileCount = FileCount + 1
MsgBox (InputDir & "" & ImportFile)
DoCmd.TransferText acImportFixed, "SPECIF", "IMPORTATION_EDI", ImportFile, False
ImportFile = Dir()
Loop
End If
MsgBox (FileCount & " fichiers EDI ont été importés dans la base.")
End Sub
EDIT : En fait j'ai trouvé l'origine du problème, Access ne prend pas les fichiers .EDI, mais en les renommant en .TXT ça fonctionne !