csv report renaming before import

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 12 daily csv reports that have a autonumber added to a standard naming
convention.

Is there anyway of renaming these files from a database so that my normal
import spec works without having to manually amend the file names.
 
Import specifications do not rely on the name of the file being imported. I
assume that you're looking for wanting to have the right filename in the
FileName argument of TransferText?

Check out the Name statement in VBA:

Name Path\Folder\OldFilename.csv As Path\Folder\NewFilename.csv
 
I have 12 daily csv reports that have a autonumber added to a standard naming
convention.

Is there anyway of renaming these files from a database so that my normal
import spec works without having to manually amend the file names.

STOLEN CODE... this belongs to Doug Steele...

Untested air-code. Note that I haven't bothered putting in error
handling if
the .txt file already exists in the folder.

Dim strFile As String
Dim strNewName As String
Dim strPath As String

strPath = "C:\Documents and Settings\SDF\"
strFile = Dir$(strPath & "*.sdf")
Do While Len(strFile) > 0

'-- CREATE THE NEW FILE NAME FROM THE OLD ONE...
strNewName = Left(strFile, Len(strFile) - 4) & ".txt"

'---THIS LINE RENAMES THE OLD FILE...
Name strPath & strFile As strPath & strNewName

'---IMPORT THE FILE
DoCmd.TransferText acImportFixed, "importspec", "SDF", _
strPath & strNewName
strFile = Dir$()
Loop
 
Post the code that you tried so that we can help debug ... and give details
about the initial file names of the .csv files.
 
Back
Top