Results 1 to 3 of 3
  1. #1
    spider_min is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2020
    Posts
    1

    Unable to print the report - "

    Hi,

    This issue happen when I am trying to generate the report. It usually populate the Excel right after I click the button. It worked just fine, and this issue happened with no reason.

    " Run-time Error '2302':

    Microsoft Access can't save the output data to the output data to the file you've selected."


    The code below:



    Private Sub cmRiskPresubawardResponses_Click()

    Dim pfn As String
    Dim q As String

    'Check Dates
    If Not IsDate(RiskPresubawardResponsesStart) Or _
    Not IsDate(RiskPresubawardResponsesEnd) Then
    MsgBox "Invalid date(s)."
    Exit Sub
    End If

    q = "Export - RiskPresubawardResponses"

    pfn = GetVariable("Risk Presubaward Reports Folder") & "" & _
    "Presubaward Report (" & _
    Format(gDateStart, "yyyy-mm-dd") & " through " & Format(gDateEnd, "yyyy-mm-dd") & ").xlsx"

    DoCmd.OutputTo acOutputQuery, q, acFormatXLSX, pfn, True

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    2302 means an object was not created.

    = OBJECT.GetVariable()
    not sure what youre trying to get out of that statement.

    why not just use:
    pfn = Dlookup(...)
    to get the file folder from a table

    or if its an object on the form (that is open):
    pfn = me.textbox





  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It would be nice if you provided the code for the function "GetVariable()", but this is how I would probably write the sub (you had unneeded concatenation-->> & "" & )
    Code:
    Private Sub cmRiskPresubawardResponses_Click()
    
        Dim pfn As String
        Dim q As String
    
        'Check Dates
        If Not IsDate(RiskPresubawardResponsesStart) Or _
           Not IsDate(RiskPresubawardResponsesEnd) Then
            MsgBox "Invalid date(s)."
            Exit Sub
        End If
    
        q = "Export - RiskPresubawardResponses"
    
        pfn = GetVariable("Risk Presubaward Reports Folder") & "Presubaward Report" & _
              Format(gDateStart, "yyyy-mm-dd") & " through " & Format(gDateEnd, "yyyy-mm-dd") & ".xlsx"
              
        DoCmd.OutputTo acOutputQuery, q, acFormat12XLSX, pfn, True
    
    End Sub
    Since you have A2016 and you write to an Excel 2016 spreadsheet, you need to use the parameter acFormat12XLSX.
    Use acFormatType of "acFormatXLSX" for Excel 2007
    Use acFormatType of "acFormat12XLSX" for Excel A2013 and later.

    see https://www.accessforums.net/showthr...503#post449503

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

Similar Threads

  1. Replies: 4
    Last Post: 11-01-2018, 11:22 AM
  2. Print a table's "LastUpdated" metadata in a report
    By Carbontrader in forum Reports
    Replies: 3
    Last Post: 03-05-2018, 04:22 AM
  3. Replies: 1
    Last Post: 09-29-2016, 03:12 AM
  4. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  5. Replies: 10
    Last Post: 09-03-2015, 01:31 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