Uknown error on send attachment.

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

===================================================
 
M

MikeJohnB

Mr or Ms Idiaz

I only answer this in order to try and assist and because no one else has
answered, I don't know enough about the e mail attachments side.

However, try to determin where the error is by either typing Stop before the
line

sbSendMessage (strfile)

(or by putting in a break line by double clicking in the margin next to the
same code line. it should highlight Red.)

and see if the error is in the form control or the function??? Once the code
has been broken, you will be able to hover over the variables to see what the
variable values are in the break mode.

Please be aware that snapshot viewer is not now supplied with Access 2007
(Or it wasn't when I installed A2007, what version are you running? A version
of Snapshot viewer for 2007 can be downloaded.

I hope this helps a little????

Regards

--
Advice to Posters.
Check your post for replies or request for more information.
Consider providing some feed back to the response you have recieved.
Kindest Regards Mike B


ldiaz said:
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

===================================================
 
L

ldiaz

Hello Mike,
I can find the error and I fixed,
thanks a lot for your recomendation.

Thanks
LD


--
Lorenzo Díaz
Cad Technician


MikeJohnB said:
Mr or Ms Idiaz

I only answer this in order to try and assist and because no one else has
answered, I don't know enough about the e mail attachments side.

However, try to determin where the error is by either typing Stop before the
line

sbSendMessage (strfile)

(or by putting in a break line by double clicking in the margin next to the
same code line. it should highlight Red.)

and see if the error is in the form control or the function??? Once the code
has been broken, you will be able to hover over the variables to see what the
variable values are in the break mode.

Please be aware that snapshot viewer is not now supplied with Access 2007
(Or it wasn't when I installed A2007, what version are you running? A version
of Snapshot viewer for 2007 can be downloaded.

I hope this helps a little????

Regards

--
Advice to Posters.
Check your post for replies or request for more information.
Consider providing some feed back to the response you have recieved.
Kindest Regards Mike B


ldiaz said:
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

===================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top