Hi,
I've reached a little bit of a brick wall with this!
In short, I've got a load of invoice's sitting in a directory which I need to import into Access. The Invoice contains 4 columns - 'Store', 'Location', 'Claimed' and 'Receieved'. The invoice number is in the title of the spreadsheet - which is always in the same format.
I've pieced together the following code, which simply searches the directory for an excel file, imports it, moves the file, and then loops until all files are processed.
Option Compare Database
Option Explicit
Sub Impo_allExcel()
Dim myfile
Dim mypath
mypath = "J:\Finance\Invoices\"
Do
myfile = Dir(mypath & "*.xls")
DoCmd.TransferSpreadsheet acImport, 8, "Tbl_Invoices", mypath & myfile, True
myfile = Dir
Application.Run "MoveFiles"
Loop Until myfile = ""
MsgBox "All Invoices are now Imported"
End Sub
Sub MoveFiles()
Dim fso
Dim myfile
Dim sfol As String, dfol As String
sfol = "J:\Finance\Invoices\" ' source folder path
dfol = "J:\Finance\Invoices\Done" ' destination folder path
myfile = Dir(sfol & "*.xls")
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
ElseIf Not fso.FolderExists(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid Destination"
This does the job! I'm sure there are more reliable ways of doing it - but it seems to work.
My problem is I would like to add in an extra field - with the Invoice number for each line of invoice data, so when I'm running future queries and reports, I've got a basis for comparison.
How should I approach this? Do I need to put the invoice number into a seperate table and then run a joining query betweent the two?
The file name format is ''com bank inv ####.xls'', or 'myfile' in the code above.
Many Thanks
Tom
I've reached a little bit of a brick wall with this!
In short, I've got a load of invoice's sitting in a directory which I need to import into Access. The Invoice contains 4 columns - 'Store', 'Location', 'Claimed' and 'Receieved'. The invoice number is in the title of the spreadsheet - which is always in the same format.
I've pieced together the following code, which simply searches the directory for an excel file, imports it, moves the file, and then loops until all files are processed.
Option Compare Database
Option Explicit
Sub Impo_allExcel()
Dim myfile
Dim mypath
mypath = "J:\Finance\Invoices\"
Do
myfile = Dir(mypath & "*.xls")
DoCmd.TransferSpreadsheet acImport, 8, "Tbl_Invoices", mypath & myfile, True
myfile = Dir
Application.Run "MoveFiles"
Loop Until myfile = ""
MsgBox "All Invoices are now Imported"
End Sub
Sub MoveFiles()
Dim fso
Dim myfile
Dim sfol As String, dfol As String
sfol = "J:\Finance\Invoices\" ' source folder path
dfol = "J:\Finance\Invoices\Done" ' destination folder path
myfile = Dir(sfol & "*.xls")
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
ElseIf Not fso.FolderExists(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid Destination"
This does the job! I'm sure there are more reliable ways of doing it - but it seems to work.
My problem is I would like to add in an extra field - with the Invoice number for each line of invoice data, so when I'm running future queries and reports, I've got a basis for comparison.
How should I approach this? Do I need to put the invoice number into a seperate table and then run a joining query betweent the two?
The file name format is ''com bank inv ####.xls'', or 'myfile' in the code above.
Many Thanks
Tom