Error #2046: The command or action 'OutputTo' isn't available now.

PC User

Registered User.
Local time
Today, 13:36
Joined
Jul 28, 2002
Messages
193
I've tried to debug and track down the source of this error, but I can't figure it our. I've researched access forums for something similar, but had no luck. Can someone help me with this code error?
Code:
Public Function OpenSnapReport(ReportName As String, Optional View As Integer, Optional _
    FilterName As String, Optional WhereCondition As String, Optional Prompt As Boolean = False, Optional Preview As Boolean = False)
        On Error GoTo Whoops
'What are all the things you want to do with a report?
'Print it,Save it with prompt'Save it in db directory,Save it in db directory and Preview it
'you can filter before using
Dim rep As Report
Dim FName As String
'open report window
'should run any load event code
    DoCmd.OpenReport ReportName, View, FilterName, WhereCondition
    'DoCmd.OpenForm "", acNormal
'set rep as report
    Set rep = Reports.Item(ReportName)
'make report invisible
    rep.Visible = False
'set filter
    If gstrFilter <> "" Then
    rep.Filter = gstrFilter
    rep.FilterOn = True
    Else
    rep.Filter = ""
    rep.FilterOn = False
    End If
'set orderby
    If gstrOrderBy <> "" Then
    Debug.Print gstrOrderBy
    rep.OrderByOn = True
    rep.OrderBy = gstrOrderBy
    Else
    rep.OrderBy = ""
    rep.OrderByOn = False
    End If
'If not printing
If View <> acNormal Then
'Pompt?
'If not set path for db dir
If Prompt = True Then
    FName = vbNullString
Else
    FName = CurrentDBDir & rep.Name & ".snp"
    'FName = fGetSpecialFolderLocation(&H5) & "\" & rep.Name & ".snp"
End If
'export to snapshot viewer
    'DoCmd.OutputTo objecttype[, objectname][, outputformat][, outputfile][, autostart][, templatefile]
    DoCmd.OutputTo acReport, rep.Name, "Snapshot Format", FName, Preview
    'DoCmd.OutputTo acOutputReport, rep.Name, acFormatSNP, FName, True
    DoEvents
    DoCmd.Close acReport, rep.Name
    Set rep = Nothing
    End If
    
OffRamp:
    Exit Function
Whoops:
    MsgBox "Error #" & Err & ": " & Err.Description
    Resume OffRamp
    
End Function
Thanks,
PC
 
Last edited:
I've had this problem long ago, but I don't remember exactly how I solved it. Maybe I can give you a hint of what I was playing with to get it work... Try to use the same code to export a report with no content except a label. If this works, you should check if it is any error in you report - such errors may be "accepted" for a print or preview, but not an outputto. Also try different export formats, expressing the format argument different ways ("Rich Text Format (*.rtf)", "Rich Text Format", acFormatRTF, ...), or leave the format argument blank, include/exclude the file extension and/or path in the file name, check if there already exists a file there, and try on different computers. ...and try all these things in combination... For me it works on some computers but not on others. It works on some w2k computers, but not on other winXP computers. The code that works for me is as following:

DoCmd.OutputTo acOutputReport, "repname", acFormatRTF, "x:\path\filename.rtf"
 
Error #2046: The command or action 'OutputTo' isn't available now. Reply to Thread

Thanks for your reply. I finally resolved the problem by first focusing on getting all the code to develop a report correct. Once that code was correct I then directed the report to the 'Output To' code. I had to use basic deductive analysis to eliminate the error.

Thanks,
PC
 

Users who are viewing this thread

Back
Top Bottom