Hi All
I am setting up a form to send multiple attachments to an email.
I have a query "qry_DwgEmail" that has an ID and a path column. On the form I have a button with the code below in the Click Event.
The code below all works fine unless the path is incorrect, so I would like some error handling to be able to either:
1) Stop the code from running and display a message box with my message.
2) Continue the loop and then have the message box display what files could not be found (Preferred).
Note, the following code was taken from one of the forums I am not 100% on what it all means.
Thanks
I am setting up a form to send multiple attachments to an email.
I have a query "qry_DwgEmail" that has an ID and a path column. On the form I have a button with the code below in the Click Event.
The code below all works fine unless the path is incorrect, so I would like some error handling to be able to either:
1) Stop the code from running and display a message box with my message.
2) Continue the loop and then have the message box display what files could not be found (Preferred).
Note, the following code was taken from one of the forums I am not 100% on what it all means.
Code:
Private Sub btn_CreateEmail_Click()
Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookAttach As Outlook.Attachment
Dim TheAttachment As String
Dim QDF As QueryDef
Dim prm As Parameter
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0) 'olMailItem
Set MyDB = CurrentDb
Set QDF = MyDB.QueryDefs("qry_DwgEmail")
For Each prm In QDF.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set MyRS = QDF.OpenRecordset
MyRS.MoveFirst
On Error GoTo Handler:
With objOutlookMsg
Do Until MyRS.EOF
TheAttachment = MyRS![directoryFullPath]
Set objOutlookAttach = .Attachments.Add(TheAttachment)
MyRS.MoveNext
Loop
Handler:
MsgBox "Not All Of The Selected Files Have Been Found" & vbCrLf & vbCrLf & "Double Click Drawing Number And ReLink File"
'.To = "myeamil@yahoo.com"
.Subject = "Profile Lighting Drawings"
.Body = "Please find attached drawings " & vbCrLf & vbCrLf & "Kind Regards"
'.Send
End With
objOutlookMsg.Display
Email_Err_Clear:
End Sub
Thanks