Save to PDF File Name AutoCreate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brilstern
    New Member
    • Dec 2011
    • 208

    Save to PDF File Name AutoCreate

    Q: How do I relate the desired filename to a field within the table of the datasource to "autoname" the file when saved.

    In the below code the filename is NewReport. I want to change this to be the [Long Name] field of each record source when it saves. Reason being in the "autoname" function is because eventually I am going to create an archive button that will save a copy for each record to a monthly folder.


    Code:
    Private Sub cmdSavePDF_Click()
    Dim strName As String
    Dim strFilter As String
    Dim strCurrentPath As String
    Dim strReportFile As String
    Dim strReport As String
    strFilter = "[SSN] = '" & Me.MemberSelect & "'"
    strName = Me.MemberSelect
    strCurrentPath = Application.CurrentProject.Path
    strReportFile = strCurrentPath & "\[B]NewReport[/B].pdf"
    strReport = "rptECR"
       
       Call DoCmd.OpenReport(ReportName:="rptECR", View:=Access.AcView.acViewReport, WhereCondition:=strFilter)
       Debug.Print "Report and path: " & strReportFile
       DoCmd.OutputTo objecttype:=acOutputReport, objectname:=strReport, outputformat:=acFormatPDF, outputfile:=strReportFile
       DoCmd.Close acReport, "rptECR"
       
    End Sub
    Let me know if there is any other information that will help find a solution. Thx

    Sgt B
  • sierra7
    Recognized Expert Contributor
    • Sep 2007
    • 446

    #2
    Hi again,
    The answer is to include the identifier in strReportFile e.g.
    Code:
    strFilter = "[SSN] = '" & Me.MemberSelect & "'" 
    strName = Me.MemberSelect 
    strCurrentPath = Application.CurrentProject.Path 
    strReportFile = strCurrentPath & "\NewReport" & strName & ".pdf"
    However, refereing back to your other question about looping through BandMembers, then this is a good example why you might want to use looping rather than have a continuous report (with page breaks) Each member would have a seperate report that could be emailed to him personally. The continuous report being more of a Control Document for management purposes.
    S7

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      Try the following as a replacement for line #10 (I'm assuming the table name is [tblECR] - change if necessary) :
      Code:
      strReportFile = DLookup(Expr:="[Long Name]", _
                              Domain:="[tblECR]", _
                              Criteria:=strFilter)
      strReportFile = Replace(strCurrentPath & "\ECR%N.PDF", "%N", strReportFile)

      Comment

      • Brilstern
        New Member
        • Dec 2011
        • 208

        #4
        NeoPa,

        That did the trick, I have never used the Dlookup function, new one to put into the toolbox. Thx

        Sierra7,

        Thx for the input, led exactly to NeoPa's example:)

        Sgt B

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          It's also possible to use recordset code to access the same data, but generally a single access (to get one bit of data) can better be handled by the Domain Aggregate functions, of which one such is DLookup().

          Comment

          • Brilstern
            New Member
            • Dec 2011
            • 208

            #6
            I see thank you both very much.

            Comment

            Working...