Export to a CSV file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramdil
    New Member
    • Dec 2007
    • 46

    Export to a CSV file

    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\AC CFIN_Group_Sale s\v2.0 Development\fil ename"

    DoCmd.TransferT ext 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
    New Member
    • Jul 2007
    • 233

    #2
    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\AC CFIN_Group_Sale s\v2.0 Development\fil ename"

    DoCmd.TransferT ext 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

    Comment

    • cori25
      New Member
      • Oct 2007
      • 83

      #3
      Code:
      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

      Comment

      • ramdil
        New Member
        • Dec 2007
        • 46

        #4
        Hi

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



        Originally posted by cori25
        Function test()
        Dim db As dao.Database
        Set db = CurrentDb

        Dim strTemp As String

        strTemp = "C:\Database\te st.csv"


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

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

        xlApp.ActiveWor kbook.SaveAs strSavePath

        'Close Excel
        xlApp.Quit
        Set xlApp = Nothing


        End Function

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          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.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            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 :)

            Comment

            Working...