csv report renaming before import

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.
 
K

Ken Snell \(MVP\)

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
 
P

pietlinden

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
 
K

Ken Snell \(MVP\)

Post the code that you tried so that we can help debug ... and give details
about the initial file names of the .csv files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top