I figured this out. It wanted me to create the destination files too, not just the directories before I could copy to it.
Having trouble exporting to text file
-
10-10-2022 - |
题
I am having some trouble exporting out to a file from VBA. Some things to be aware of are that JobDetail
is a valid export SpecName and 2_JobDetail
is a query that combines some info with stuff from other fields and tables. When I try to run I get the error like below on my DoCmd.TransferText
method call. Advice? am I doing something wrong? code below.
Public Function exportJobDetailRecs(dateStr As String)
'Docmd.TransferText(acexport,specName,TableName, FileName,HasfieldNames,HTMLTableName)
DoCmd.TransferText acExport, _
"JobDetail", _
"2_JobDetail", _
"P:\Folder1\Folder2\Tracker\" + CStr(dateStr + "_OrderStatus_jobdets.txt")
exportJobDetailRecs = CStr(dateStr + "_OrderStatus_jobdets.txt")
End Function
Some questions people have asked:
- Yes - Do you have full permission to write to the file (i.e. full permission to the folder as well as the text file if you are not creating it with code)
- Yes - Check path (folder name with space/etc) for mistakes.
- and I'm copying with Shift-Right click, then copy as Path, and adding a trailing
\
manually
- and I'm copying with Shift-Right click, then copy as Path, and adding a trailing
- Yes - Have you try exporting manually and overwriting your existing spec and see if that works? If so, try runs the code again afterward
- Yes - Have you confirmed JobDetail is an export spec instead of an import spec?
- and manual exports work fine
- 3-50 - How many records does 2_JobDetail currently return?
- Same - Try the export (temporarily) to "P:\Folder1\Folder2\Tracker\a.txt"
- It doesn't care what folder (that exists) I point it to, it wont go
- None - Also make sure that there are no punctuation marks in strDate
- http://pastie.org/private/0kdf2wvkg1wug5physna for the function I use to make dateStr
解决方案
不隶属于 StackOverflow