I am using the following VBA to automatically import csv files into an access table:
Function ImportCSV()
Dim InputDir, ImportFile As String, tblName As String, FinalName As String, specName As String
Dim InputMsg As String
InputDir = "c:\testFiles\"
ImportFile = Dir(InputDir & "\*.csv")
Do While Len(ImportFile) > 0
'tblName = Left(ImportFile, (InStr(1, ImportFile, ".") - 1)) 'Use this to import each file into separate tables.
tblName = "tbl_Validation" 'I use this to import all my files into one table.
specName = "INTMR_Sites"
DoCmd.TransferText acImportDelim, specName, tblName, InputDir & ImportFile, True
ImportFile = Dir
Loop
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
'If fs.FileExists("c:\YOUR DIR WHERE THE FILES LAND\*.csv") Then
fs.MoveFile "c:\testFiles\*.csv", "c:\testHistory\"
End Function
An example filename of my csv files is:
SAGAS_INTMR_ENVSA_REMCO_20050715102115.CSV
What I now need to do is add a column within my table that can store the "date" which is found within the file name (first 8 numerals). Ie, in the above example, 15/07/2005 needs to be stored in a date field.
Is there any way I can do this using VBA?
Cheers.
Function ImportCSV()
Dim InputDir, ImportFile As String, tblName As String, FinalName As String, specName As String
Dim InputMsg As String
InputDir = "c:\testFiles\"
ImportFile = Dir(InputDir & "\*.csv")
Do While Len(ImportFile) > 0
'tblName = Left(ImportFile, (InStr(1, ImportFile, ".") - 1)) 'Use this to import each file into separate tables.
tblName = "tbl_Validation" 'I use this to import all my files into one table.
specName = "INTMR_Sites"
DoCmd.TransferText acImportDelim, specName, tblName, InputDir & ImportFile, True
ImportFile = Dir
Loop
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
'If fs.FileExists("c:\YOUR DIR WHERE THE FILES LAND\*.csv") Then
fs.MoveFile "c:\testFiles\*.csv", "c:\testHistory\"
End Function
An example filename of my csv files is:
SAGAS_INTMR_ENVSA_REMCO_20050715102115.CSV
What I now need to do is add a column within my table that can store the "date" which is found within the file name (first 8 numerals). Ie, in the above example, 15/07/2005 needs to be stored in a date field.
Is there any way I can do this using VBA?
Cheers.