Results 1 to 6 of 6
  1. #1
    Vol71 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    7

    Renaming a pdf. report in email

    I am trying to email a report and rename the report after the referenced NCR# currently selected on my form. My codes works for putting the referenced NCR# in my email subject, but I am having issues renaming the report and the error is with the SetProperty line bolded below. When I click my email button, I get Run-time error 32004: The contronl name "Supplier Chargebacks" is mispelled or refers to a control that doesen't exists.



    Thanks

    Private Sub Command587_Click()

    Dim stReport As String
    Dim stWhere As String
    Dim stSubject As String
    Dim NCRNum As String

    NCRNum = Forms![NCR Input Form]![NCR #]
    stSubject = "Supplier Chargebacks NCR " & NCRNum
    stReport = "Supplier Chargebacks"
    stWhere = "[NCR #] = " & "'" & NCRNum & "'"

    DoCmd.OpenReport stReport, acViewPreview, "", stWhere, acWindowNormal, ""
    DoCmd.SetProperty stReport, acPropertyCaption, "Supplier Chargebacks NCR " & NCRNum
    DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", , , , stSubject, , True, ""

    DoCmd.Close acReport, stReport
    DoCmd.SendObject acSendReport

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You can set the caption before you send this way...
    Code:
        Dim rpt
        Dim sRpt As String
        
        sRpt = "rReport1"
        DoCmd.OpenReport sRpt, acViewDesign
           Set rpt = Reports(sRpt)
           rpt.Caption = "Supplier Chargebacks NCR " & NCRNum
    
    
           'rpt.RecordSource = pvQry
           'rpt.OrderByOn = True
           'rpt.OrderBy = sFld
        DoCmd.Close acReport, rpt.Name, acSaveYes
        DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", , , , stSubject, , True, ""

  3. #3
    Vol71 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    7
    Thanks, I was able to get the report pdf. to be rename and attach to email, but now my where condition no longer works on the OpenReport. It prints all reports together in one pdf. and doesn't filter them by NCR #. What am I doing wrong? Thanks

  4. #4
    Vol71 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    7
    Quote Originally Posted by Vol71 View Post
    Thanks, I was able to get the report pdf. to be rename and attach to email, but now my where condition no longer works on the OpenReport. It prints all reports together in one pdf. and doesn't filter them by NCR #. What am I doing wrong? Thanks
    Private Sub Command587_Click()
    Dim stReport As String
    Dim stWhere As String
    Dim stSubject As String
    Dim NCRNum As String

    NCRNum = Forms![NCR Input Form]![NCR #]
    stSubject = "Supplier Chargebacks NCR " & NCRNum
    stReport = "Supplier Chargebacks"
    stWhere = "[NCR #] = " & "'" & NCRNum & "'"
    Dim rpt
    Dim sRpt As String

    sRpt = "Supplier Chargebacks"
    DoCmd.OpenReport sRpt, acViewDesign, , stReport
    Set rpt = Reports(sRpt)
    rpt.Caption = "Supplier Chargebacks NCR " & NCRNum

    'rpt.RecordSource = pvQry
    'rpt.OrderByOn = True
    'rpt.OrderBy = sFld
    DoCmd.Close acReport, rpt.Name, acSaveYes
    DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", , , , stSubject, , True, ""


    DoCmd.Close acReport, stReport
    DoCmd.SendObject acSendReport

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    the QUERY behind the report does the filtering. Usu from a form where you picked an NCR.

    query criteria: where [ncr] = forms!frmRpt!cboNCR


  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,634
    Options:

    1. as ranman suggests - report RecordSource is a dynamic parameterized query that refers to input control on a form for filter (I never use dynamic parameterized queries)

    2. open filtered report in PrintPreview and SendObject will then act on the open report object instead of from the navigation pane
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-18-2015, 11:24 AM
  2. Email report as body of email (RTF)
    By TheDeceived in forum Programming
    Replies: 4
    Last Post: 07-23-2012, 06:39 AM
  3. Renaming a report before SendObject
    By kingdoz in forum Reports
    Replies: 2
    Last Post: 11-17-2011, 08:22 PM
  4. Replies: 4
    Last Post: 04-13-2011, 10:11 AM
  5. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums