L
ldiaz
I have a code in a form command button and a module code to send attachments
like .pdf, .doc or other besides an .snp report that is exported previously,
but the code does not work,
I can't find the reason, can you please take a look at it and advise?..
Thanks a lot in advanced for your help..
Form Code
========================================
Private Sub sendreport_Click()
On Error GoTo Err_sendreport_Click
If Me.[Path_Loc1] <> "" Then
'Declare file path
Dim strfile As String
strfile = Me.[Path_Loc1]
'save report as Snap Shot before sending
DoCmd.OutputTo acOutputReport, "rpt_Incident", acFormatSNP, "C:\Documents
and Settings\ldiaz\My Documents\Medical System\Medical
Report\rpt_Incident.snp"
'Run sbSendMessage fuction
sbSendMessage (strfile)
Else
DoCmd.OutputTo acOutputReport, "rpt_Incident", acFormatSNP,
"C:\Documents and Settings\ldiaz\My Documents\Medical System\Medical
Report\rpt_Incident.snp"
sbSendMessage
End If
Exit_sendreport_Click:
Exit Sub
Err_sendreport_Click:
' MsgBox Err.Description
' Resume Exit_EmailReport_Click
End Sub
=================================================
Module Code:
Option Compare Database
Option Explicit
=================================================
Sub sbSendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
On Error GoTo ErrorMsgs
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip =
..Recipients.Add([Forms]![Frm_Incident]![User_05])
objOutlookRecip.Type = olTo
Set objOutlookRecip =
..Recipients.Add([Forms]![Frm_Incident]![Customer_Email])
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "We are notifiying under Incident Number: " &
[Forms]![Frm_Incident]![ID_MedicalSystem_ID]
.Body = "" & vbCrLf & _
"* See rpt_Incident.Snp for Stored Information." & vbCrLf & _
"* See other Attachment for more information added to this incident
file." & vbCrLf & _
"(PDF or other attachment files are included on the email if this was
added first to the incident file!)"
.Importance = olImportanceHigh 'High importance
Set objOutlookAttach = .Attachments.Add("C:\Documents and
Settings\ldiaz\My Documents\Medical System\Medical Report\rpt_Incident.snp")
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Display
' .Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
[Forms]![Frm_Incident]![SentEmail_Date].Value = Format(Now(),
"Mmm-dd-yy hh:nn:ss Am/Pm")
ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail" & _
"addresses to send your message. For more information" & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
Else
MsgBox Err.Number, Err.Description
End If
End Sub
===================================================
like .pdf, .doc or other besides an .snp report that is exported previously,
but the code does not work,
I can't find the reason, can you please take a look at it and advise?..
Thanks a lot in advanced for your help..
Form Code
========================================
Private Sub sendreport_Click()
On Error GoTo Err_sendreport_Click
If Me.[Path_Loc1] <> "" Then
'Declare file path
Dim strfile As String
strfile = Me.[Path_Loc1]
'save report as Snap Shot before sending
DoCmd.OutputTo acOutputReport, "rpt_Incident", acFormatSNP, "C:\Documents
and Settings\ldiaz\My Documents\Medical System\Medical
Report\rpt_Incident.snp"
'Run sbSendMessage fuction
sbSendMessage (strfile)
Else
DoCmd.OutputTo acOutputReport, "rpt_Incident", acFormatSNP,
"C:\Documents and Settings\ldiaz\My Documents\Medical System\Medical
Report\rpt_Incident.snp"
sbSendMessage
End If
Exit_sendreport_Click:
Exit Sub
Err_sendreport_Click:
' MsgBox Err.Description
' Resume Exit_EmailReport_Click
End Sub
=================================================
Module Code:
Option Compare Database
Option Explicit
=================================================
Sub sbSendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
On Error GoTo ErrorMsgs
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip =
..Recipients.Add([Forms]![Frm_Incident]![User_05])
objOutlookRecip.Type = olTo
Set objOutlookRecip =
..Recipients.Add([Forms]![Frm_Incident]![Customer_Email])
objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
.Subject = "We are notifiying under Incident Number: " &
[Forms]![Frm_Incident]![ID_MedicalSystem_ID]
.Body = "" & vbCrLf & _
"* See rpt_Incident.Snp for Stored Information." & vbCrLf & _
"* See other Attachment for more information added to this incident
file." & vbCrLf & _
"(PDF or other attachment files are included on the email if this was
added first to the incident file!)"
.Importance = olImportanceHigh 'High importance
Set objOutlookAttach = .Attachments.Add("C:\Documents and
Settings\ldiaz\My Documents\Medical System\Medical Report\rpt_Incident.snp")
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Display
' .Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
[Forms]![Frm_Incident]![SentEmail_Date].Value = Format(Now(),
"Mmm-dd-yy hh:nn:ss Am/Pm")
ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail" & _
"addresses to send your message. For more information" & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
Else
MsgBox Err.Number, Err.Description
End If
End Sub
===================================================