save report with criteria as pdf file in A07

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuxalot
    New Member
    • Feb 2009
    • 200

    #1

    save report with criteria as pdf file in A07

    I may be way off base here with regard to my code, but this is my attempt. Veteran coders...no laughs please, I'm new to Access.

    I am trying to create a pdf from an Access report. Here is the code on my main form reports tab:

    private sub:
    Code:
    Dim stDocName As String
    
    stDocName = Me.lstReportName.Column(1)        'the name of the report
    
            DoCmd.OpenReport stDocName, acPreview
                 If Me.chkSaveAsPdf.Value = -1 Then
                     Call SaveAsPdf(stDocName)
                 End If
    and here is the function:
    Code:
    Public Function SaveAsPdf(stDocName As String)
        
        Dim rptDate As String
        Dim strAppPath As String
        Dim rptPath As String
        Dim MyFilename As String
        
        rptDate = Now()
        'MsgBox rptDate
        
        'store the full path to our current project
        strAppPath = CurrentProject.Path & "\"
    
        'store the file in a different folder depending on the date
        rptPath = "strAppPath" & Format(rptDate, "yyyy")
    
        'store the filename as MM-DD-YYYY-[reportname].pdf
        MyFilename = Format(rptDate, "mm") & _
                     "-" & Format(rptDate, "dd") & Format(rptDate, "yyyy") & _
                     "-" & "stDocName" & ".pdf"
    
        'save the file. Once you see it works, you can change True to False so that the file created
        'is not opened after completion.
        DoCmd.OutputTo acOutputReport, "stDocName", acFormatPDF, "rptPath" & MyFilename, True, , , acExportQualityPrint
    
    End Function
    The error I'm getting is 2059 "cannot find the object 'stDocName'

    Any help is appreciated.
  • tuxalot
    New Member
    • Feb 2009
    • 200

    #2
    sorted now, disregard.

    Thanks,

    Tux

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Hi Tux. For anyone interested, could you tell us what the problem was?

      As far as I can see it will be that in line 24 you accidentally placed the name of variable strDocName inside double quotes - hence treating the name of the variable as a literal instead of substituting its value in the call, leading to the error where 'strDocName' was not the correct name of the document concerned. Correct?

      -Stewart

      Comment

      • tuxalot
        New Member
        • Feb 2009
        • 200

        #4
        Stewart, your analysis is spot on. Actually since I will only be using this from my main form, I put the code in a sub. Here it is:

        Code:
                Dim stDocName As String
                Dim rptDate As String
                Dim strAppPath As String
                Dim rptPath As String
                Dim MyFilename As String
        
                'report is local, so open it
                stDocName = Me.lstReportName.Column(1)
        
                DoCmd.OpenReport stDocName, acPreview
        
                'if save to pdf checkbox is checked, then save pdf
                If Me.chkSaveAsPdf.Value = -1 Then
        
                    rptDate = Now()
        
                    'store the full path to our current project
                    strAppPath = CurrentProject.Path & "\"
        
                    'store the file in a different folder depending on the date stated in a field called "Date"
                    rptPath = strAppPath        'not working
        
                    'store the filename as MM-DD-YYYY-[report name].pdf
                    MyFilename = Format(rptDate, "mm") & "-" & Format(rptDate, "dd") & "-" & Format(rptDate, "yyyy") & " - " & stDocName & ".pdf"
        
                    'save the pdf. Once working, you can change 'True' to 'False' below so that the pdf file created
                    'is not opened after completion.
                    DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, rptPath & MyFilename, False, , , acExportQualityPrint
                    MsgBox "Your pdf file named:" & vbCr & " " & MyFilename & " " & vbCr & "has been successfully saved."
                End If
        Line 21 is not creating a sub-dir in the db's path, so I could use some help there. I intend to modify the code here to include (3) options for each report selected, save to pdf, print preview, and print. Also, I might try to give the EU the option to select the path to save the pdf. Something like: If Me.chkSaveAsPdf .Value = -1 Then [unhide txtSavePdfPath].

        I'm curious how the print-to-pdf function will react when deploying this db as an A07 run time version to sites without the full version of Access. I suspect it will not work. Can anyone confirm this, and if true anyone have a solution? Maybe perhaps include another pdf print driver in the deployment package?

        Thanks all for your help!

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          Tux,

          You should probably realise that posting your new (and quite unrelated) question in here is defeating your own purpose. This is fundamentally a non-viewed thread apart from those experts already subscribed. This is one of the reasons it's against the site rules. I suggest you repost the question as a new thread, thereby all interested experts are likely to see it and someone may be able to help.

          Comment

          • tuxalot
            New Member
            • Feb 2009
            • 200

            #6
            Thanks NeoPa. No need to repost, I'll test this myself now that I have a pc with A03 installed.

            Comment

            Working...