Email With Attachments Using Access 2007 (1 Viewer)

Colorado Spring

Registered User.
Local time
Today, 12:59
Joined
Dec 10, 2005
Messages
36
Morning all...

Wondering if I can adjust my code, below, to add form attachments to my email. Here is the code I'm using...

Private Sub Send_Email_Click()
On Error GoTo Err_Send_Email_Click

Dim strTo As String
strTo = Me.To

Dim strSubject As String
strSubject = Me.Subject

Dim strMess As String
strMess = Me.Message

DoCmd.SendObject , , acFormatRTF, Me!To, , , Me!Subject, Me!Message, True, ""

Exit_Send_Mail_Click:
Exit Sub

Err_Send_Email_Click:
MsgBox Err.Description

Resume Exit_Send_Mail_Click

End Sub

Thanx in advance :)
Karen
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:59
Joined
Aug 30, 2003
Messages
36,140
Depends on what you mean by "form attachments". If you want to send a query, report, etc, you can use that. See VBA help for more info. If you want to send an attachment not associated with the db, you'll need automation:

http://support.microsoft.com/?kbid=161088
 

CEH

Curtis
Local time
Today, 13:59
Joined
Oct 22, 2004
Messages
1,187
What you are going to send needs to be in the "Docmd.sendobject" line.......for example a report......

DoCmd.SendObject acSendReport, "rptNameOfReport", acFormatRTF, Me!To, , , Me!Subject, Me!Message, True, ""
 

Colorado Spring

Registered User.
Local time
Today, 12:59
Joined
Dec 10, 2005
Messages
36
Thanx for your reply CEH...

I have a table "Canned Emails" with fields including EmailID, Subject, Message, and Attachments. I have a second table "Sent Canned Emails" with fields including Sent ID, Email ID, Date, and To.

I have a form based on a query of the two tables, which includes fields from both tables, and a command button to "Send Email". The code I posted earlier sends the email to Outlook for edit. However, I don't know how to adjust my code so that the email adds my record attachment(s), most of which are Word documents but all of which are stored in the "Canned Emails" table as "Attachments".

Can you advise?

Thanx :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:59
Joined
Aug 30, 2003
Messages
36,140
As noted in post 2, you can't send Word documents with SendObject. See the link about automation.
 

Colorado Spring

Registered User.
Local time
Today, 12:59
Joined
Dec 10, 2005
Messages
36
Oh, ok pbaldy; I'll take a look. I didn't think this really applied to what I wanted to do since the attachment(s) are, in fact, associated with and stored within the db.

Thanx :)
Karen
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:59
Joined
Aug 30, 2003
Messages
36,140
That was poorly worded on my part, Karen. I assume you mean you have paths to pre-existing documents stored in the db. SendObject can't send those.
 

konecny.tomas

New member
Local time
Today, 11:59
Joined
Oct 12, 2012
Messages
9
Hi guys.
I want to kindly ask you for help.
I’ve read all relevant threads.
I want to attach my currently open report to the e-mail using VBA.
I googled the code below, works fine.
Please advice how to attach currently open report.
Can I modify the attachment name?
Many thanks.


Dim objOL As Object
Dim objMail As Object
Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(olMailItem)

strBody = "Attached, please find a copy of the " & NameofCompanyBolded & _
" letter for your review, and an electronic version of the Questionnaire. A paper copy of these documents is also being sent to you." & vbCrLf & vbCrLf & _
"Please let me know if you have any questions."

objMail.To = strTo
objMail.CC = strCC
objMail.BCC = strBcc
objMail.Subject = strSubject

'Display Email
objMail.Display

objMail.body = strBody & objMail.body & vbCrLf & AfterSignatureCCs
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:59
Joined
Aug 30, 2003
Messages
36,140
With that method you can only attach a saved file. You can use OutputTo in this code to do that, or switch to SendObject, which will send the report directly.
 

Users who are viewing this thread

Top Bottom