I'm trying to import a semi colon delimited .csv
file into an access database using the following code. I've set up an import specification which works called "Import-FACTS". and VBA can see the specification (by putting OLEacc.CurrentProject.ImportExportSpecifications(0)
into the watch window.
Sub ImportFacts()
Dim OLEacc As Access.Application
Set OLEacc = GetObject("", "Access.Application")
OLEacc.OpenCurrentDatabase (ThisWorkbook.Path & "\" & "LargeData.accdb")
OLEacc.DoCmd.TransferText TransferType:=acImportDelim, _
SpecificationName:="Import-FACTS",_
TableName:="Facts",_
Filename:=ThisWorkbook.Path & "\Facts.csv",_
HasFieldNames:=False
End Sub
However I get the debug message:
Run-time error '3625' The text file specification "Import-Facts" does not exist You cannot import export or link using the specification.
Any ideas?
ImportExportSpecifications
are saved jobs.SpecificationName
is something else. What happens if you open an Access session (without Excel) and attempt the sameTransferText
... replacingThisWorkbook.Path
with the path to the folder which contains the CSV file?DoCmd.TransferText TransferType:=acImportDelim, SpecificationName:="Import-FACTS", TableName:="Facts", FileName:="C:\***\Facts.csv", HasFieldNames:=False
. Do you know how I create an import specification rather than a saved job? I hadn't realised there was a difference.