By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

Export to a CSV file

P: 46
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
Feb 21 '08 #1
Share this Question
Share on Google+
5 Replies


MindBender77
100+
P: 234
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
Feb 21 '08 #2

cori25
P: 83
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
Feb 21 '08 #3

P: 46
Hi

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



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
Feb 22 '08 #4

NeoPa
Expert Mod 15k+
P: 31,768
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.
Feb 22 '08 #5

NeoPa
Expert Mod 15k+
P: 31,768
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 :)
Feb 22 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.