5
votes

I created a test MS Access DB to export a table to Excel and a text file.

This works for Excel:

DoCmd.OutputTo acOutputQuery, "QryExportToExcel", _
acFormatXLS, XFile, False

For the text file, I created a specification and used this code

DoCmd.TransferText acExportDelim, "Mytable Import Specification", "mytable", "D:\myfolder\test1.txt", False

In the error message, I get "test1#txt".

The Microsoft Office Access database engine could not find the object
"test1#txt". Make sure the object exists and that you spell its name
and the path name correctly.

Error which i got

I tried creating test1.txt in the same path. To my surprise, this deleted the file which is already present.

Software: MS ACCESS 2007

4
Sorry HansUp FileDir is "D:\myfolder\". For convinence i hardcoded path in this question. - shanmugamgsn
Oh yes you are right. there is a problem with SpecificationName. If i remove that one i can export. But i need a delimeter for this export. how can i achieve without SpecicationName . Do you have any code? - shanmugamgsn
Hey HansUp i got the error man. Its because i was using a Import Specification for Exporting a file. So i removed it and gave a Export Specification Name - shanmugamgsn
You are exporting a delimited file, do you really need a specification at all? Are your delimiters non-standard? - Fionnuala

4 Answers

1
votes

The Microsoft Office Access databasse engine could not find the object "test1#txt". Make sure the object exists and that you spell its name and path name correctly.

This is a generic (and rather useless) error message that Access outputs in case anything goes wrong. One example would be a misspelled field name in the import/export specification.

You can get the "real" error message by trying the import operation "manually" in the Access user interface (rather than through code).

1
votes

The question author reported the problem was "because I was using an Import Specification for Exporting a file."

They resolved the problem by using an Export Specification.

0
votes

Because you are doing DoCmd.TransferText, Access is expecting that the file Test1.txt exists in that location. Try creating the file first, and then do a transfer of the text.

You can try this code before the export to create the file:

Public Sub CreateExportFile()
 Dim strFileName As String
 Dim SomeStringToOutput

 strFileName = "d:\myfolder\test1.txt"
 Open strFileName For Output As #1

End Sub
0
votes

I was having a similar situation and found that a file schema.ini was in the destination folder. This was created when an acExportMerge was performed previously and it caused this error. Make sure that file has been deleted prior to executing a new TransferText.