GODZILLA
Registered User.
- Local time
- Today, 00:52
- Joined
- Mar 15, 2010
- Messages
- 70
Hello,
I have been atempting to minipulate this bit of code to allow me to import around 300 files at onc in to a table. All the files have the same structure.
Does anyone have the solution im looking for?
I have been atempting to minipulate this bit of code to allow me to import around 300 files at onc in to a table. All the files have the same structure.
Does anyone have the solution im looking for?
Code:
Private Sub cmdImport_Click()
On Error GoTo ErrHandler
Dim oFSystem As Object
Dim oFolder As Object
Dim oFile As Object
Dim sFolderPath As String
Dim SQL As String
Dim i As Integer
sFolderPath = [B]"C:\My Documents\"[/B]
Set oFSystem = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSystem.GetFolder(sFolderPath)
For Each oFile In oFolder.files
If Right(oFile.Name, 4) = ".dbf" Then
SQL = "Insert into [tblFORMGUIDE]" _
& " Select """ & Left(oFile.Name, 7) & """ as [Key],*" _
& " from " & Left(oFile.Name, Len(oFile.Name) - 4) _
& " IN """ & sFolderPath & """ ""dBASE 5.0;"""
DoCmd.SetWarnings False
DoCmd.RunSQL SQL
DoCmd.SetWarnings True
i = i + 1
End If
Next
MsgBox i & " dbf files were imported."
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub