Importing CSV files usinf code

  • Thread starter Thread starter terry
  • Start date Start date
T

terry

I am trying to import .csv files into an Access 2002
database. I am usinf code which I have previously used
in Access 97, but for some reason it doesnt appear to
work. The code specifies a file name but also uses a
wildcard to allow for the changes in file name each wee
in accrodance with a date, i.e. filename010704.csv.

This is the code I am using can anyone help.
'DoCmd.TransferText acImportDelim, "CCAT_Hierarchy", _
"tblCCAT", "P:\ccppro_ss_ccat_people*.csv", Yes
 
Try determining what the current name of the file is, and store that in a
variable.

For example:

strFileName = Dir("P:\*.csv)
If Len(strFileName) > 0 then
DoCmd.TransferText acImportDelim, "CCAT_Hierarchy", _
"tblCCAT", "P:\" & strFileName, Yes
End If

If there's a chance of multiple CSV files in that folder, the following will
retrieve all of them. You may need to add some way of determining which
one(s) you want:

strFileName = Dir("P:\*.csv)
Do While Len(strFileName) > 0 then
DoCmd.TransferText acImportDelim, "CCAT_Hierarchy", _
"tblCCAT", "P:\" & strFileName, Yes
strFileName = Dir()
End If
 
Back
Top