Import, Rename .csv files with date created as field

  • Thread starter Thread starter Shawn C
  • Start date Start date
S

Shawn C

Hi,

I have a need to import new csv files from a directory into my databse, and
then rename the files so that they do not get re-imported. I also want to
include the date created of each file as a field in my table. I have the
following which imports the files:

Dim strFolder As String
Dim strFile As String

strFolder = "\\pbdsftpnp.main.pbd.com\PBDSFTPNP\hasbro\"
strFile = Dir(strFolder & "*.csv")
Do While Len(strFile) > 0
DoCmd.TransferText acImportDelim, "FileImportSpecs", "FileImport", strFolder
& strFile, True
strFile = Dir()

Loop

But I don't know how to rename the files, and where to place this command in
the dode, and I don't know how to inlude the date created (of each csv file)
as a field within the record.

Any help will be greatly appreciated!
 
I've figured out how to rename the file so it doesn't get imported more than
once, by changing the code as follows:

Dim strFolder As String
Dim strFile As String
Dim strNewName As String

strFolder = "\\pbdsftpnp.main.pbd.com\PBDSFTPNP\hasbro\"
strFile = Dir(strFolder & "*.csv")
Do While Len(strFile) > 0
DoCmd.TransferText acImportDelim, "FileImportSpecs", "FileImport", strFolder
& strFile, True
strNewName = Left(strFile, Len(strFile) - 4) & ".imp"
Name strFolder & strFile As strFolder & strNewName
strFile = Dir()


Loop

But I need help on how to update a field in the destination table with the
appropriate date created value of the csv file it came from.

Thanks!
 
Hi Shawn,

I am also trying to inlude the date created (of each csv file) as a field
within the record. So far I haven't found anything but if I do I'll post an
answer.

Nice code though for the csv import

Géraud
 
Back
Top