CathyLynnHughes
IS-IT--Management
I’m having a problem with an Outlook attachment when I rename it using Visual Basic in Access 2003. The attachment name is supposed to change every time a new record is entered in Access and the action field is exited. The attachment name is supposed to change to the ATN (phone number) on the current record.
I used the following code to rename the record attachment and send the e-mail out. The record successfully renames in the database. Unfortunately, the attachment line in the e-mail gives the previous name (PortOut Test Report) instead of the new name (the phone number in the current record). When I open the attachment in the E-mail, it shows the updated record information. How can I fix the name in the attachment line of the e-mail?
Cathy
'Declare variable for report attachment.
Dim strEMailReportAttachment As String
'Assign report name to the report attachment variable.
strEMailReportAttachment = "PortOut Test Report"
'Declare variable
'to be used as new name for report attachment.
Dim strRenamedEMailReportAttachment As String
'Assign ATN (phone number) value
'as new name for report attachment
strRenamedEMailReportAttachment = Me.ATN
'Declare variable for subject line.
Dim strEMailSubjectLine As String
'Assign values of ATN (Phone #), PON and Ver (Version) to the subject line variable.
strEMailSubjectLine = "LSR Confirmation for " & Me.ATN & ", " & Me.PON & ", " & Me.Ver
'Selected action cause save record macro to be run,
'report attachment to be renamed
'and determines code to send E-mail.
'Send report attachment in E-mail.
'Use acSendReport for the formats,
'acFormatRTF (Rich Text File) or acFormatSNP.
'Formatted for To, Cc and Subject lines in E-mail:
'To is "", Cc is "Michael Zades",
'Subject is strEMailSubjectLine [ATN (Phone #),
'PON and Ver (Version)],
'MessageText is "This order has been rejected.", EditMessage is True and
'TemplateFile is None.
'If Action is Rejected, rename attachment
'report using ATN, make due date a blank,
'save record and send e-mail.
If Me.Action = "Rejected" Then
Me.DD = Null
DoCmd.RunMacro "mcrSaveRecord", 1
DoCmd.Rename strRenamedEMailReportAttachment, acReport, strEMailReportAttachment
DoCmd.SendObject acSendReport, strRenamedEMailReportAttachment, acFormatSNP, _ "", "Michael Zades", , _ strEMailSubjectLine, "This order has been rejected.", True
DoCmd.Rename strEMailReportAttachment, acReport, strRenamedEMailReportAttachment
End If
End Sub
I used the following code to rename the record attachment and send the e-mail out. The record successfully renames in the database. Unfortunately, the attachment line in the e-mail gives the previous name (PortOut Test Report) instead of the new name (the phone number in the current record). When I open the attachment in the E-mail, it shows the updated record information. How can I fix the name in the attachment line of the e-mail?
Cathy
'Declare variable for report attachment.
Dim strEMailReportAttachment As String
'Assign report name to the report attachment variable.
strEMailReportAttachment = "PortOut Test Report"
'Declare variable
'to be used as new name for report attachment.
Dim strRenamedEMailReportAttachment As String
'Assign ATN (phone number) value
'as new name for report attachment
strRenamedEMailReportAttachment = Me.ATN
'Declare variable for subject line.
Dim strEMailSubjectLine As String
'Assign values of ATN (Phone #), PON and Ver (Version) to the subject line variable.
strEMailSubjectLine = "LSR Confirmation for " & Me.ATN & ", " & Me.PON & ", " & Me.Ver
'Selected action cause save record macro to be run,
'report attachment to be renamed
'and determines code to send E-mail.
'Send report attachment in E-mail.
'Use acSendReport for the formats,
'acFormatRTF (Rich Text File) or acFormatSNP.
'Formatted for To, Cc and Subject lines in E-mail:
'To is "", Cc is "Michael Zades",
'Subject is strEMailSubjectLine [ATN (Phone #),
'PON and Ver (Version)],
'MessageText is "This order has been rejected.", EditMessage is True and
'TemplateFile is None.
'If Action is Rejected, rename attachment
'report using ATN, make due date a blank,
'save record and send e-mail.
If Me.Action = "Rejected" Then
Me.DD = Null
DoCmd.RunMacro "mcrSaveRecord", 1
DoCmd.Rename strRenamedEMailReportAttachment, acReport, strEMailReportAttachment
DoCmd.SendObject acSendReport, strRenamedEMailReportAttachment, acFormatSNP, _ "", "Michael Zades", , _ strEMailSubjectLine, "This order has been rejected.", True
DoCmd.Rename strEMailReportAttachment, acReport, strRenamedEMailReportAttachment
End If
End Sub