Can't seem to save an exported file using MSAccess Outputto command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pdxrichard
    New Member
    • Mar 2008
    • 1

    Can't seem to save an exported file using MSAccess Outputto command

    Windows XP - Server 2003 - Access 2007 VBA - Code behind a form

    Here is my code.

    Why can't I find the exported file if the directories exist and there are no permission problems? Isn't a save command implied with the outputto command?


    [CODE=vb]Private Sub DisplayReport()
    Dim rptSls As Report

    Select Case (rptType)
    Case RPT_DESIGNER, RPT_SHOWROOM
    DoCmd.OpenRepor t gRptSlsName, acViewPreview

    Set rptSls = Reports(gRptSls Name)
    rptSls![txtRptFtr] = gRptFtrByDesign er
    Case Else
    DoCmd.OpenRepor t gRptSlsSamples, acViewPreview

    Set rptSls = Reports(gRptSls Samples)
    rptSls![txtRptFtr] = gRptFtrByDNSamp les
    End Select

    DoEvents

    Select Case jabBrand
    Case gBrandHF
    rptSls![txtRptHdr] = gRptHdrBrandHF

    Case gBrandIFAB
    rptSls![txtRptHdr] = gRptHdrBrandIFA B
    End Select

    DoEvents

    '//Populate Total Header with Sales Dates
    rptSls![txtMMYY01] = ConvDateName(gs trSlsRoll01)
    rptSls![txtMMYY02] = ConvDateName(gs trSlsRoll02)
    rptSls![txtMMYY03] = ConvDateName(gs trSlsRoll03)
    rptSls![txtMMYY04] = ConvDateName(gs trSlsRoll04)
    rptSls![txtMMYY05] = ConvDateName(gs trSlsRoll05)
    rptSls![txtMMYY06] = ConvDateName(gs trSlsRoll06)
    rptSls![txtMMYY07] = ConvDateName(gs trSlsRoll07)
    rptSls![txtMMYY08] = ConvDateName(gs trSlsRoll08)
    rptSls![txtMMYY09] = ConvDateName(gs trSlsRoll09)
    rptSls![txtMMYY10] = ConvDateName(gs trSlsRoll10)
    rptSls![txtMMYY11] = ConvDateName(gs trSlsRoll11)
    rptSls![txtMMYY12] = ConvDateName(gs trSlsRoll12)
    rptSls![txtMMYY13] = ConvDateName(gs trSlsRoll13)

    DoEvents

    Call ExportCollRepor t

    Set rptSls = Nothing
    End Sub

    Private Sub ExportCollRepor t()
    On Error GoTo Handle_Err

    Dim strRPT As String

    strRPT = GetOutputFileNa me

    Debug.Print strRPT

    DoCmd.OutputTo acOutputReport, gRptSlsName, acFormatSNP, strRPT


    Exit_Err:
    DoCmd.Close acReport, gRptSlsName, acSaveNo
    Call DisplayMsg(" Exported File: " & strRPT)
    Exit Sub

    Handle_Err:
    Select Case Err.Number
    Case 2501
    ' The OutputTo action was cancelled.
    Resume Exit_Err
    Case Else
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Err
    End Select
    End Sub[/CODE]
    Last edited by Scott Price; Mar 21 '08, 07:32 PM. Reason: code tags
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. DoCmd.OutputTo does what it says it does - you tell it what to output and it will do so, if it can. I think you need to trace why the report output did not happen as expected, rather than pursue the filename issue. If there is a valid filename provided it will indeed export to that file, as long as the report that is to be output has content to export. The failure tends to suggest there was no report to output.

    I note the use of a number of global variables to store report names etc. This makes reading and interpreting your code more difficult. There are issues in your code resulting from their use.

    Your Select Case statement selects two different reports, identified by globals gRptSlsName and gRptSlsSamples. Your export routine refers only to report gRptSlsName. If you are setting up gRptSlsSamples you are not going to export it unless you explicitly refer to it, which does not happen at present. If gRptSlsName is not set then your export routine will have no report to export at all.

    You are also outputting the report whilst it is still open in preview mode to set control values. This works OK in my tests in Access 2003, but I can't verify that this will still hold for Access 2007. In any event it is not good practice to be exporting an unsaved report that is still open for modification at the time.

    If you resolve the issues mentioned and you still cannot output you are going to have to trace your code a step at a time, setting break points and examining the various crucial elements, including the name of the report that is passed to the OutputTo method, as you step through.

    -Stewart

    Comment

    Working...