Link to home
Start Free TrialLog in
Avatar of PJVicto
PJVicto

asked on

Syntax to OutputTo acOutputReport using string values

I am trying to pass a string as the ObjectName  and OutputFile values in the OutputTo acOutputReport function.  It works fine when I explicitly use the report name and path name in double quotes, but when I us the stDocName and strPath strings, I get an error message.  Can you help me with the syntax?

Error message received:  The report name ''rpt_All'' you entered in either the property sheet or macro is misspelled or refers to a report that doesn't exist.


Private Sub cmdCreatePDF_Click()
 
On Error GoTo Err_cmdCreatePDF_Click
 
 
 
    Dim strPath As String
 
    strPath = Me.Mail_Attachment_Path
 
    
 
    Dim stDocName As String
 
    Select Case Me.frame_Choices
 
        Case 1
 
        stDocName = "rpt_ANA"
 
        Case 2
 
            stDocName = "rpt_SUP"
 
        Case 3
 
            stDocName = "rpt_CSM"
 
        Case 4
 
            stDocName = "rpt_All"
 
        End Select
 
        
 
    
 
    'Send report as a snapshot  (works fine)
 
    DoCmd.OutputTo acOutputReport, "rpt_RollUP", _
 
    acFormatSNP, "Q:\SPG\SRG\Operations\StatusReporting_Testing\Rollup.snp", True
 
  
 
    works fine
 
    DoCmd.OutputTo acOutputReport, "rpt_All", _
 
    acFormatSNP, "Q:\SPG\SRG\Operations\StatusReporting_Testing\testRollup.snp", True
 
    
 
    Does not work
 
    DoCmd.OutputTo acOutputReport, "'" & stDocName & "'", _
 
    acFormatSNP, "'" & strPath & "'" & "'" & stDocName & "'", True
 
 
 
Exit_cmdCreatePDF_Click:
 
    Exit Sub
 
 
 
Err_cmdCreatePDF_Click:
 
    MsgBox Err.Description
 
    Debug.Print Err.Description
 
    Resume Exit_cmdCreatePDF_Click

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you may need to add "\"


DoCmd.OutputTo acOutputReport, stDocName , acFormatSNP, strPath &"\"& stDocName , True