Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    output

    All, using access 2010. I have 3 queries I need to export to 3 different excel spreadsheets to one folder. So when I use the code



    DoCmd.OpenQuery "qry1"
    DoCmd.OutputTo acOutputQuery, "qry1", acFormatXLSX

    How can I save the query to folder created at the time of the export? Ex. create the folder to C:\20110811NewFolderName export query without having the user to have to create the folder before saving
    . Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Bing: access vba create folder if doesn't exist
    http://www.techonthenet.com/access/f...file/mkdir.php
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ok. I tried this but I need to add the date in front of the name folder:
    Code:
    MkDir "C:\Directory\mainfolder\& Format(Date, "yyyymmdd")folder
    This doesn't work??

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    MkDir "C:\Directory\mainfolder\" & Format(Date, "yyyymmdd") & "folder"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ok when I try to declare it; error states "end of statement expected" and highlights "C:\Directory\mainfolder\"

    Code:
    spath = MkDir "C:\Directory\mainfolder\" & Format(Date, "yyyymmdd") & "folder"
    Code:
    DoCmd.OutputTo acOutputQuery,  sPath "qryMidnite", acFormatXLS

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    spath = "C:\Directory\mainfolder\" & Format(Date, "yyyymmdd") & "folder"
    MkDir strPath
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I am getting this Error "Path/File access error

    Code:
    Dim sPath As String
    sPath = "C:\Directory\mainfolder\" & Format(Date, "yyyymmdd") & "folder"
    MkDir sPath
    DoCmd.OutputTo acOutputQuery, sPath, "qryMidnite", acFormatXLS
    I tried MkDir in place of sPath and with sPath. Still erroring

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    MkDir works for me but I only tested at the C root. Maybe there is a permissions issue somewhere along the path.

    Do a test of code creating folder at C root.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    o ok. It created the folder but didn't export the files. Something is wrong with my code to output the queries.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The parameters given for the OutputTo arguments are out of order and incomplete.

    DoCmd.OutputTo acOutputQuery, "query name", acFormatXLS, strPath & "\" & "file name.xls"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    It worked but really slow. I'll work on it. Thanks.

  12. #12
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    how do I get spaces between the dates. ex. "yyyymmdd"= 20140812 I would like 2014 08 11

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Format(Date, "yyyy mm dd")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I got this. Thanks but I do no get a space between the date and the folder name. 2014 08 12foldername

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Format(Date, "yyyy mm dd ")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-23-2014, 04:35 PM
  2. Replies: 4
    Last Post: 12-30-2013, 05:51 PM
  3. How to query for this output?
    By seemi143 in forum Queries
    Replies: 1
    Last Post: 12-04-2013, 02:37 AM
  4. Output to pdf
    By TOMMY.MYERS668 in forum Programming
    Replies: 3
    Last Post: 02-25-2013, 11:03 AM
  5. .txt output from report
    By dhopper in forum Reports
    Replies: 1
    Last Post: 08-05-2011, 12:01 PM

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