koolwaters
Active Member
- Joined
- May 16, 2007
- Messages
- 403
I am trying to attach and email an Excel workbook from a command button on a form.
The code below opens Outlook, attaches the file but when I enter the email address and click Send, I get a message box "Outlook cannot send this item".
The code below sends the file to the recipient but my challange is that I want to be able to enter the recipient's email address directly from Outlook as it will not always be the same email.
Thanks for any feedback.
The code below opens Outlook, attaches the file but when I enter the email address and click Send, I get a message box "Outlook cannot send this item".
Code:
Private Sub cmdEmailApplication_Click()
On Error GoTo Err_cmdEmailApplication_Click
Dim strMessageSubject As String
Dim strBody As String
Dim strTitle As String
Dim Msg As Outlook.MailItem
strBody = "Please see attached Application Form"
strMessageSubject = "Application Form"
Set gappOutlook = GetObject(, "Outlook.Application")
Set Msg = gappOutlook.CreateItem(olMailItem)
With Msg
.Subject = strMessageSubject
.Body = strBody
.Attachments.Add GetDBPath & "Application Form Templates\Application Form.xls"
.Display
End With
Exit_cmdEmailApplication_Click:
Exit Sub
Err_cmdEmailApplication_Click:
MsgBox Err.Description
Resume Exit_cmdEmailApplication_Click
End Sub
The code below sends the file to the recipient but my challange is that I want to be able to enter the recipient's email address directly from Outlook as it will not always be the same email.
Code:
Private Sub cmdEmailApplication_Click()
On Error GoTo Err_cmdEmailApplication_Click
Dim strMessageSubject As String
Dim strBody As String
Dim frm As Access.Form
Dim strTitle As String
Dim Msg As Outlook.MailItem
strBody = "Please see attached Application Form"
strMessageSubject = "Application Form"
strToEmail = "mkcc@caribsurf.com"
Set gappOutlook = GetObject(, "Outlook.Application")
Set Msg = gappOutlook.CreateItem(olMailItem)
With Msg
.To = strToEMail
.Subject = strMessageSubject
.Body = strBody
.Attachments.Add GetDBPath & "Application Form Templates\Application Form.xls"
.Send
End With
Exit_cmdEmailApplication_Click:
Exit Sub
Err_cmdEmailApplication_Click:
MsgBox Err.Description
Resume Exit_cmdEmailApplication_Click
End Sub
Thanks for any feedback.