Results 1 to 7 of 7
  1. #1
    fpmsi is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    16

    Export to excel (File Name issues)

    I am looking for a way to modify this code to name the export file differently.



    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryCombined_forexport", "export.xls"

    I am looking for the export file to be export(date).xls

    where (date) is the current date of export.


    Or can i create a save as dialog box for the user to name the file themselves?

    Thanks
    Ryan.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Try this:

    Code:
     
    Dim ExportFile as String
    ExportFile = "export_" & Format(Date, "yyyy-mm-dd") & ".xls"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryCombined_forexport", ExportFile
    I like to put the yyyy first, because when you sort over a period of more than one year the files still stay in chronological order. Otherwise, they get sorted by whatever you have first. If mm is first - all your January files will be first . . .

    I hope this helps!

  3. #3
    fpmsi is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    16
    Thank you that worked great but always goes to "my documents". Can I specify where it goes? I thought it was always going to the same folder the database was located in before.

    Thanks

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Try some variation of this to get it to where you need it:

    Code:
    Dim MytPath, ExportFile as String
     
    MyPath = "C:\MyFolder\"
    ExportFile = Mypath & "export_" & Format(Date, "yyyy-mm-dd") & ".xls"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryCombined_forexport", ExportFile
    Let me know if that works.

  5. #5
    fpmsi is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    16
    Thanks. Because the database will be used by multiple people would like to not specify a folder and instead use the current db folder

    Trying to incorporate this:
    GetDBPath = CurrentProject.Path & "\"

    so ExportFile would = GetDBPath & ExportFile

    Not having any luck though.

  6. #6
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Here is what I use in a multi user environment where users may want to save the exported query to different locations. This line of code is used to place the file on the users desktop and then they can move it to where ever they wish.

    MyPath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\"

    Alan

  7. #7
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    fpmsi,
    Why does
    GetPath = CurrentProject.Path & "\"
    not work for you?

    I just tried this:

    Code:
     
    MyPath = CurrentProject.Path & "\"
    ExportFile = Mypath & "export_" & Format(Date, "yyyy-mm-dd") & ".xls"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryCombined_forexport", ExportFile
    and it did what I think you are attempting.

    What happens when you try it?

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

Similar Threads

  1. Export all tables to 1 excel file
    By vestlink in forum Programming
    Replies: 5
    Last Post: 10-03-2011, 02:45 AM
  2. Replies: 3
    Last Post: 02-01-2011, 10:18 AM
  3. File Export "sort" issues
    By jgelpi16 in forum Programming
    Replies: 24
    Last Post: 09-15-2010, 12:14 PM
  4. Export a simple query result to an excel file
    By wop_nuno in forum Import/Export Data
    Replies: 1
    Last Post: 05-21-2009, 04:18 AM
  5. Issues with dating when importing excel file
    By Lainie in forum Import/Export Data
    Replies: 0
    Last Post: 01-22-2009, 10:50 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