iamko
Programmer
- Aug 12, 2013
- 1
I got some tips from here so I thought i'd share this. This will import all the .dbf files in the sFolderPath directory into access.
Private Sub ImportDBF()
On Error Resume Next 'change to On Error GoTo ErrHandler if you want to see errors.
Dim oFSystem As Object
Dim oFolder As Object
Dim oFile As Object
Dim sFolderPath As String
Dim i As Integer
sFolderPath = "C:\Temp\OTG\DataOnly\" 'Only thing you need to change
Set oFSystem = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSystem.getfolder(sFolderPath)
For Each oFile In oFolder.files
If Right(oFile.Name, 4) = ".dbf" Then
'MsgBox oFile.Name
'MsgBox Replace(oFile.Name, ".dbf", "")
DoCmd.TransferDatabase acImport, "dbase IV", sFolderPath, acTable, oFile.Name, Replace(oFile.Name, ".dbf", "")
End If
Next
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
Private Sub ImportDBF()
On Error Resume Next 'change to On Error GoTo ErrHandler if you want to see errors.
Dim oFSystem As Object
Dim oFolder As Object
Dim oFile As Object
Dim sFolderPath As String
Dim i As Integer
sFolderPath = "C:\Temp\OTG\DataOnly\" 'Only thing you need to change
Set oFSystem = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSystem.getfolder(sFolderPath)
For Each oFile In oFolder.files
If Right(oFile.Name, 4) = ".dbf" Then
'MsgBox oFile.Name
'MsgBox Replace(oFile.Name, ".dbf", "")
DoCmd.TransferDatabase acImport, "dbase IV", sFolderPath, acTable, oFile.Name, Replace(oFile.Name, ".dbf", "")
End If
Next
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub