Jordan2000
Registered User.
- Local time
- Today, 21:19
- Joined
- Nov 4, 2004
- Messages
- 24
Ok I already wrote a macro to import xls files from a local ore remote dir.
but no I want to keep record of files that where imported to the Database.
And I dont want to upload files that already are in the DB.
Becouse this is going to be a automated process on a daily basis.
I alsow need a table with all the import erros and a msg that will be generated.
here is the code I already Have.
I hope that you can help me.
but no I want to keep record of files that where imported to the Database.
And I dont want to upload files that already are in the DB.
Becouse this is going to be a automated process on a daily basis.
I alsow need a table with all the import erros and a msg that will be generated.
here is the code I already Have.
Code:
Private Sub Import_Click()
Dim strFileName As String, strFileName1 As String, sTableName As String, strPath As String
Dim i As Integer
Dim fs As Object
Set fs = Application.FileSearch
With fs
.LookIn = "C:\XlsImport-Export\ActualScotland" 'define dir
.fileName = "*.xls" 'define file type
If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderDescending) > 0 Then
For i = 1 To .FoundFiles.Count
strPath = .FoundFiles(i)
strFileName = Dir(strPath)
strFileName1 = Left$([strFileName], InStr(1, [strFileName], ".") - 1)
sTableName = Mid(Replace(strFileName1, " ", ""), InStr(1, (Replace(strFileName1, " ", "")), "-") + 1)
Sfilename = strFileName
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found. And you want to Import " & strFileName
'lookup if Sfilename excist in imported files if true then next else import
'if import then ammend the file name to the imported files table
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"" & sTableName & "", strPath, True
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
I hope that you can help me.