is there a way to change pdf attachement name in sendobject code? (1 Viewer)

Abouya

Registered User.
Local time
Today, 13:42
Joined
Oct 11, 2016
Messages
88
Hello,

I'm trying to add RequisitionID number to the attached pdf in sendObject code. is there a way to do this?

Code:
Private Sub MailReport_Click()
On Error GoTo MailReport_Click_Err
    Dim emailto As String
    emailto = List5.ItemData(List5.ItemsSelected.Item(0))
    
    If StrPtr(emailto) = 0 Or Len(emailto) = 0 Then
        Cancel = True
   Else
   
    DoCmd.SendObject acReport, "ReportOrderDetailQuery", "PDFFormat(*.pdf)", emailto, "", "", "PO Requisition #" & Report_ReportOrderDetailQuery![RequisitionID], "Requestor: " & Report_ReportOrderDetailQuery![fk_RequestorID] & vbNewLine & "Request Date: " & Report_ReportOrderDetailQuery![RequestDate] & vbNewLine & "Status: " & Report_ReportOrderDetailQuery![Status] & vbNewLine & "Total: $" & Report_ReportOrderDetailQuery![Text625] & vbNewLine & vbNewLine & "Regards," & vbCrLf, True, ""
    Beep
    MsgBox "Your email was successfully sent!", vbOKOnly, ""


MailReport_Click_Exit:
    Exit Sub

MailReport_Click_Err:
    MsgBox "The operation was cancelled"
    Resume MailReport_Click_Exit
   
   End If

End Sub
 

Ranman256

Well-known member
Local time
Today, 16:42
Joined
Apr 9, 2015
Messages
4,337
it looks like you did it by putting it in the subject or the body.
tho you wouldnt use the report variabvle, use the FORM variable....me.requestID
 

Abouya

Registered User.
Local time
Today, 13:42
Joined
Oct 11, 2016
Messages
88
it looks like you did it by putting it in the subject or the body.
tho you wouldnt use the report variabvle, use the FORM variable....me.requestID

thanks. Trying it now.

My concern now is how to add RequisitionID to the file/report being attached in the email.

i tried to add the field to the attached file but that doesn't work.

Here is the code

Code:
Private Sub MailReport_Click()
On Error GoTo MailReport_Click_Err
    
    Dim sExistingReportName As String
    Dim sAttachmentName As String
    Dim emailto As String
    
    emailto = List5.ItemData(List5.ItemsSelected.Item(0))
    
    If StrPtr(emailto) = 0 Or Len(emailto) = 0 Then
        Cancel = True
   Else
   sExistingReportName = "ReportOrderDetailQuery"    'Name of the Access report Object to send
    sAttachmentName = "PO Requisition #" & Report_ReportOrderDetailQuery![RequisitionID]    'Name to be used for the attachment in the e-mail

    'The code to make it happen
    DoCmd.OpenReport sExistingReportName, acViewPreview, , , acHidden
    Reports(sExistingReportName).Caption = sAttachmentName    'by changing the report caption
                                                        'you effectively change the name
                                                        'used for the attachment in the
                                                        '.SendObject method
    DoCmd.SendObject acReport, "sExistingReportName", "PDFFormat(*.pdf)", emailto, "", "", "PO Requisition #" & Report_ReportOrderDetailQuery![RequisitionID], "Requestor: " & Report_ReportOrderDetailQuery![fk_RequestorID] & vbNewLine & "Request Date: " & Report_ReportOrderDetailQuery![RequestDate] & vbNewLine & "Status: " & Report_ReportOrderDetailQuery![Status] & vbNewLine & "Total: $" & Report_ReportOrderDetailQuery![Text625] & vbNewLine & vbNewLine & "Regards," & vbCrLf, True, ""
    Beep
    MsgBox "Your email was successfully sent!", vbOKOnly, ""


MailReport_Click_Exit:
    Exit Sub

MailReport_Click_Err:
    MsgBox "The operation was cancelled"
    Resume MailReport_Click_Exit
   
   End If

any help world be appreciated. thanks.
 
Last edited:

Users who are viewing this thread

Top Bottom