Connecting Tech Pros Worldwide Help | Site Map

Export to a CSV file

Member
 
Join Date: Dec 2007
Posts: 46
#1: Feb 21 '08
Hi All
Can any one please help me in problem.I want to export details of a access table to a csv file
for that i have written the following code

filepath = "\\accs03-003fs\Databases\Development\ACCFIN_Group_Sales\v2. 0 Development\filename"

DoCmd.TransferText acExportDelim, , "tab_Customers", filepath

but after executing the above command i am getting "Cannot update database or Object is read only".Why is it so..
then one more doubt is that can i export a result of a query to csv file rather than table name.Thanks in advance
MindBender77's Avatar
Familiar Sight
 
Join Date: Jul 2007
Location: Pittsburgh,Pa USA
Posts: 232
#2: Feb 21 '08

re: Export to a CSV file


Quote:

Originally Posted by ramdil

Hi All
Can any one please help me in problem.I want to export details of a access table to a csv file
for that i have written the following code

filepath = "\\accs03-003fs\Databases\Development\ACCFIN_Group_Sales\v2. 0 Development\filename"

DoCmd.TransferText acExportDelim, , "tab_Customers", filepath

but after executing the above command i am getting "Cannot update database or Object is read only".Why is it so..

I believe the problem is deriving from your filepath. I would suggest designing a macro that transfers text first. I find it easier to troubleshoot problems using macros, then migrate your finds to code.

Hope this points you in the right direction,
Bender
cori25's Avatar
Member
 
Join Date: Oct 2007
Location: Milford, CT
Posts: 83
#3: Feb 21 '08

re: Export to a CSV file


Expand|Select|Wrap|Line Numbers
  1. Function test()
  2. Dim db As dao.Database
  3. Set db = CurrentDb
  4.  
  5. Dim strTemp As String
  6.  
  7. strTemp = "C:\Database\test.csv"
  8.  
  9.  
  10. DoCmd.OutputTo acOutputTable, "TableName", acFormatXLS, strTemp, 1
  11.  
  12. 'Save the workbook
  13. Dim strSavePath As String
  14. Dim strFileNm As String
  15. strSavePath = "C:\Database\Example.xls"
  16.  
  17. xlApp.ActiveWorkbook.SaveAs strSavePath
  18.  
  19. 'Close Excel
  20. xlApp.Quit
  21. Set xlApp = Nothing
  22.  
  23.  
  24. End Function
Member
 
Join Date: Dec 2007
Posts: 46
#4: Feb 22 '08

re: Export to a CSV file


Hi

Thanks for reply..what is the object xlApp refered,is it excel object



Quote:

Originally Posted by cori25

Function test()
Dim db As dao.Database
Set db = CurrentDb

Dim strTemp As String

strTemp = "C:\Database\test.csv"


DoCmd.OutputTo acOutputTable, "TableName", acFormatXLS, strTemp, 1

'Save the workbook
Dim strSavePath As String
Dim strFileNm As String
strSavePath = "C:\Database\Example.xls"

xlApp.ActiveWorkbook.SaveAs strSavePath

'Close Excel
xlApp.Quit
Set xlApp = Nothing


End Function

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#5: Feb 22 '08

re: Export to a CSV file


It's the Excel application.
After a closer look though, it may need some extra code to set it up before use. Check out Application Automation for what you may need to add for this to work.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#6: Feb 22 '08

re: Export to a CSV file


Quote:

Originally Posted by cori25

Function test()
Dim db As dao.Database
Set db = CurrentDb
...
'Close Excel
xlApp.Quit
Set xlApp = Nothing

End Function

Cori, I've noticed a number of your helpful responses in the forum, so I don't want to sound critical.
Please remember to use the [ CODE ] tags in future when including code in your posts. I've updated this one for you.

Welcome to TheScripts & keep up the good work :)
Reply