Results 1 to 8 of 8
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    Export report

    Hi all, using access 2016. I have a button on a form to export a query on to the users desktop in a folder. This was working up until a few days ago.

    Code:
    Private Sub Command9_Click()
    Dim reportname As String
    Dim theFilePath As String
    reportname = "qryPrintrecord"
    theFilePath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\Output"
    theFilePath = theFilePath & reportname & "_" & Format(Date, "yyyy-mm-dd") & ".xls"
     
    DoCmd.acOutputQuery, reportname, acfortmatXLS, theFilePath, True
    MsgBox "Look on your desktop for the report."
    The error msg MSaccess cant save the output data to the file you've selected.



    I tried docmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, reportname, the Filepath true...
    This worked but when the user went to open the dile error msg the file format n extension of qry dont match. The file may be corrupted...pls help..thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is that the actual code? I would have assumed it was

    DoCmd.OutputTo...

    Should there be a \ after Output in the file path?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    sorry; left that off but was there....Still not working....

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What is the actual code?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Code:
    Private Sub Command9_Click()
    Dim reportname As String
    Dim theFilePath As String
    reportname = "qryPrintrecord"
    theFilePath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\Output\"
    theFilePath = theFilePath & reportname & "_" & Format(Date, "yyyy-mm-dd") & ".xls"
     
    DoCmd.acOutputQuery, reportname, acfortmatXLS, theFilePath, True
    MsgBox "Look on your desktop for the report."
    I get the error msg: MSaccess cant save the output data to the file you've selected...The file is .xls. Do you think that has anything to do with it?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I can't see that being the actual code. I'm not on a computer right now but I can't imagine either of the items in red being valid:

    DoCmd.acOutputQuery, reportname, acfortmatXLS
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    The syntax is

    expression.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding, OutputQuality)

    it looks like you want to output a query, so the DoCmd statement would look like
    Code:
    DoCmd.OutputTo acOutputQuery, reportname, acFormatXLS, theFilePath, True



    To output a report, you could also try
    Code:
    DoCmd.OutputTo acOutputReport, reportname, acFormatXLS, theFilePath, True



    Code:
    Private Sub Command9_Click()
        Dim reportname As String
        Dim theFilePath As String
        reportname = "qryPrintrecord"
        theFilePath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\Output\"
        theFilePath = theFilePath & reportname & "_" & Format(Date, "yyyy-mm-dd") & ".xls"
        
        Debug.Print theFilePath
    
        DoCmd.OutputTo acOutputQuery, reportname, acFormatXLS, theFilePath, True
    
        MsgBox "Look on your desktop for the report."
    End Sub

  8. #8
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Thanks all for responding...I am trying to export a query ...sorry the reportname is throwing u off. Maybe I'm getting the error because of getusername??? Environ(username)

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

Similar Threads

  1. Export report
    By slimjen in forum Reports
    Replies: 2
    Last Post: 07-19-2019, 07:12 AM
  2. Export Report To PDF
    By ekoziko in forum Access
    Replies: 8
    Last Post: 04-06-2018, 02:16 PM
  3. Export Report to PDF
    By Ganymede in forum Import/Export Data
    Replies: 2
    Last Post: 03-16-2016, 08:55 AM
  4. Export Report to PDF
    By cuddles in forum Reports
    Replies: 10
    Last Post: 05-21-2014, 09:28 AM
  5. Export report to jpg
    By isdm in forum Reports
    Replies: 1
    Last Post: 04-16-2010, 10:00 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