Results 1 to 6 of 6
  1. #1
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121

    Question Export Multiple Query in one CSV file

    I have created button and put this code to export in excel file. It works perfectly fine. It give me two tab Query1 and Query2 and file name Output_Result_15-Jan-2018.xlsx

    Dim xl As Object
    DoCmd.TransferSpreadsheet acExport, , "Query1", "C:\Input\Output_Result_" & Format(Date, "MMM-DD-YYYY") & ".xlsx", True


    DoCmd.TransferSpreadsheet acExport, , "Query2", "C:\Input\Output_Result_" & Format(Date, "MMM-DD-YYYY") & ".xlsx", True


    Set xl = CreateObject("Excel.application")
    xl.workbooks.Open ("C:\Input\Output_Result_" & Format(Date, "MMM-DD-YYYY") & ".xlsx")
    xl.Visible = True
    Set xl = Nothing


    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    But I want same result in csv file. I changed to some code for csv but it gives me only result of Query2 and not Query1. Where I am making mistake , kindly help me out.



    Dim xl As Object
    DoCmd.TransferText acExportDelim, , "Query1", "C:\Input\Output_Result_" & Format(Date, "MMM-DD-YYYY") & ".csv", True
    DoCmd.TransferText acExportDelim, , "Query2", "C:\Input\Output_Result_" & Format(Date, "MMM-DD-YYYY") & ".csv", True


    Set xl = CreateObject("Excel.application")
    xl.workbooks.Open ("C:\Input\Output_Result_" & Format(Date, "MMM-DD-YYYY") & ".csv")
    xl.Visible = True
    Set xl = Nothing

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    CSV files to not have 'tabs' (ala worksheets).
    they are single flat files.

    youd export 2 CSV, then open excel, then IMPORT TEXT.
    Which is really doing more work.

  3. #3
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    thanks, helps me also. Was also wondering is there a way to export to Microsoft Excel Comma Seperated Value file system , in place of simple CSV file.

    Regards
    Deepak Gupta

  4. #4
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    excel is not comma separated. It READS comma sep files easily.
    So either export as excel,
    or
    export as CSV. (which excel can always read)

  5. #5
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by ranman256 View Post
    CSV files to not have 'tabs' (ala worksheets).
    they are single flat files.

    youd export 2 CSV, then open excel, then IMPORT TEXT.
    Which is really doing more work.
    Thank for your reply. You mean it does not work like excel. What If I export as excel then save as to csv?

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Once exported as an Excel file you can then do anything that Excel allows, including saving it as a csv. Remember, however, that Excel will save one tab at a time and if you use the same csv file name for the second tab it will overwrite what is already there.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export query to a csv file.
    By swedni in forum Import/Export Data
    Replies: 3
    Last Post: 01-13-2015, 08:01 AM
  2. Replies: 2
    Last Post: 10-15-2014, 02:23 AM
  3. Replies: 10
    Last Post: 09-17-2014, 08:23 AM
  4. vba to Export Multiple Sheets to xlsx File
    By jhrBanker in forum Import/Export Data
    Replies: 3
    Last Post: 09-23-2013, 01:00 PM
  5. Replies: 1
    Last Post: 08-12-2013, 09:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums