Link to home
Start Free TrialLog in
Avatar of rogerdjr
rogerdjrFlag for United States of America

asked on

Getting an Odd error Run-time 2006 when exporting a CSV file - seems to be substituting the "#" sign for the "." in the export file name

I am getting this odd error - Experts-Exchange-Question-2019-10-2.docxseems to be substituting the "#" sign for the "." in the export file name


SpreadSheetName = Forms![0_masterdatafrm]![DefaultContrId] & " " & Forms![0_masterdatafrm]![DefaultContrIdTxt] & " Wkly Cnstr Mtg Notes " & Format(Me![MeetingNumber], "000") & " " & Format(Me![MeetingDate], "mm-dd-yyyy") & " " & TableToExport & ".csv"

MsgBox SpreadSheetName & vbNewLine & vbNewLine & "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\" & SpreadSheetName
Results –
 
DoCmd.TransferText acExportDelim, , TableToExport, "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\" & SpreadSheetName, False
Results –
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

How about using a much simpler name for export filename e.g. C:\Temp\myExport.csv to actually test the export functionality...if that works ,work your way substituting one thing at a time.
Avatar of rogerdjr

ASKER

Did that - "Test.csv" works fine

Other spreadsheets with similar naming string work fine - appears to be the delimited file that is acting up

Went to  delimited file because the table has 19,000 items and it was giving an error that it was to many items for a spreadsheet
At first probably it would be a good idea to avoid too much formatting on the name....just follow a rule like myExcel10272019 and  you should be fine.
Interesting that on a lot of lines the transferSpreadsheet bombs out......i don't use it so i don't know it had that limitation...on the other hand using automation you can easily bypass this as you will append data on chunks....i think i had recently around 50,000 lines for a client of mine  exported in chunks of 1000s...its a bit slower that the builtin mechanism but if Excel can handle the load so does this
Avatar of Norie
Norie

How about replacing the '.' after 198008 with something else?

In fact it might be an idea to replace any '.' in the filename with something else.
SpreadSheetName = Replace(Forms![0_masterdatafrm]![DefaultContrId] & " " & Forms![0_masterdatafrm]![DefaultContrIdTxt] & " Wkly Cnstr Mtg Notes " & Format(Me![MeetingNumber], "000") & " " & Format(Me![MeetingDate], "mm-dd-yyyy") & " " & TableToExport, ".", "-") & ".csv"

Open in new window

FYI

These code lines work fine for a smaller table

TableToExport = "81_ConstrMtgNotesWkgTableOfFiguresTbl"

SpreadSheetName = Rstx![ContractId] & " " & Rstx![ContractDescrp] & " Wkly Cnstr Mtg Notes " & Format(Me![MeetingNumber], "000") & " " & Format(Me![MeetingDate], "mm-dd-yyyy") & " " & TableToExport & ".xls"
           
DoCmd.OutputTo acOutputTable, TableToExport, "MicrosoftExcel(*.xls)", "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\" & SpreadSheetName, False
You're not showing the resulting file names.  The last '.' in a Windows file name is the extension separator.  Sometimes applications limit the acceptable extensions that you can use.

https://en.wikipedia.org/wiki/Filename
The example that successfully executes is

   19008.001-001 Crocker Roof Wkly Cnstr Mtg Notes 007 10-23-2019 81_ConstrMtgNotesWkgTableOfFiguresTbl.xls

The one that fails is

   19008.001-001 Crocker Roof Wkly Cnstr Mtg Notes 007 10-23-2019 81_ConstrMtgNotesWkgTbl.csv
Was "Test.csv" exporting the same data?
yes

what seems to be happening is this command seems seems to be plugging in  the # symbol for the . symbol
Do you have a screenshot or something that shows that?
See the attachment with the posting
Experts-Exchange-Question-2019-10-2.docx
Interesting.  Try a shorter file name with '.' in it.  Note that it says it's a Microsoft Access problem, not a Windows problem.  This is the only page I found that talks about error 2006 and it appears to be a generic error.

https://www.solvusoft.com/en/errors/runtime-errors/microsoft-corporation/microsoft-access/2006-the-object-name-you-entered-doesn-t-follow-microsoft-office-access-object-naming-rules/
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rogerdjr

Have you tried my suggestion of replacing any '.' in the name  with another character?
Used this code to solve the problem - works great

                SpreadSheetName = Forms![0_masterdatafrm]![DefaultContrId] & " " & Forms![0_masterdatafrm]![DefaultContrIdTxt] & " Wkly Cnstr Mtg Notes " & Format(Me![MeetingNumber], "000") & " " & Format(Me![MeetingDate], "mm-dd-yyyy") & " " & TableToExport & ".csv"

                DoCmd.TransferText acExportDelim, , TableToExport, "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\temp.csv", False
                VBA.FileCopy "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\temp.csv", "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\" & SpreadSheetName
                VBA.Kill "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\temp.csv"

Thanks to all
You are welcome!
Why FileCopy/Kill?

You could use Name.
Dim strPath As String
Dim strTempName As String

    strPath = "J:\Projects\_CM-OwnerRep\ProjMngmtDataBase\Ref Proj Spreadsheets - Current\"
    
    strTempName = "temp.csv"
    
    DoCmd.TransferText acExportDelim, , TableToExport, strPath & strTempName, False
    
    Name strPath & strTempName As strPath & SpreadSheetName

Open in new window

@rogerdjr:  Thanks!  Glad I was able to help….