Import problems

DaDutch

Registered User.
Local time
Today, 19:01
Joined
May 19, 2005
Messages
10
Hey there,
I'm trying to write a code for importing a certain sheet from all excel workbooks in one folder into an access database.
This is the code i came up so far:

Sub Command14_Click()

DoCmd.SetWarnings False

Dim Bytchoice As Byte

Dim Pad, Bestand As String

Dim Naam() As String


Dim i As Long

Pad = "C:\my documents\excel\"

i = 0

Bestand = Dir(Pad & "*.xls", vbNormal)

Do While Bestand <> ""

If Bestand <> "." And Bestand <> ".." Then

If (GetAttr(Pad & Bestand) And vbNormal) = vbNormal Then

i = i + 1

End If

End If

Bestand = Dir

Loop



Beep

Bytchoice = MsgBox("Het aantal gevonden aanmeldingsformulieren is: " & i, vbOKCancel, "Aanvraagformulieren")

If Bytchoice = vbCancel Then

Exit Sub

End If

ReDim Naam(i)

i = 0





Bestand = Dir(Pad & "*.xls", vbNormal)
Do While Bestand <> ""


If Bestand <> "." And Bestand <> ".." Then


If (GetAttr(Pad & Bestand) And vbNormal) = vbNormal Then

i = i + 1

Naam(i) = Pad & Bestand




DoCmd.TransferSpreadsheet acImport, 8, "tbl_import", Naam(i), True, "Sheet4!"

End If

End If

Bestand = Dir

Loop



Beep

MsgBox "Alle ontvangen Excel-aanmeldingsformulieren zijn verwerkt.", vbOKOnly, "Import formulieren gereed"



Exit Sub


End Sub


This code works seems to be working ok, i mean at least it shows how many file were found, but then as soon as i press ok to start importing it comes up with the message:

Run-time error '3274', "External table isn't in the expected format."

Does anybody have an idea on how to solve this???
When i do a manual import of the same file, trough get external data/import, then it works fine.

Greetz,
Rutger
 

Users who are viewing this thread

Back
Top Bottom