Link to home
Start Free TrialLog in
Avatar of lehi52
lehi52

asked on

How to get subject to merge automatically into email

How do I get the subject to merge into this access database.  See the attached database.  SOmeone was helping me get it all set up,  but the one thing that is missing in the code is auto filling in the subject from the tblbodytemplate table.  I think I need to add a subject column in the table.  

It works by click the send email button which merges into my default email program.
1.accdb
Avatar of Gozreh
Gozreh
Flag of United States of America image

Yes, you should add new field "Subject", then you will need to add in the subject  
DLookup("Subject", "tblBodyTemplate", "TemplateID=" & Form_frmSelectTemplate.TemplateID)

Open in new window

Avatar of lehi52
lehi52

ASKER

I added subject and included Body text and it pulled an error. I need it to pul both the subject and the body text into that email.  
DLookup("Subject", "BodyText", "tblBodyTemplate", "TemplateID=" & Form_frmSelectTemplate.TemplateID)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gozreh
Gozreh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lehi52

ASKER

That is good to know.  I will probably ask another question then on how to automatically pull the subject with the body text.
Your code here should be
   Dim strBody As String, strBodyText As String
   Dim strSubject As String
   strBody = "Dear " & Me.Connam_Name & vbCrLf & vbCrLf & "Here you will find the attached report......"
   
   DoCmd.OpenForm "frmSelectTemplate", , , , , acDialog
   strBodyText = DLookup("BodyText", "tblBodyTemplate", "TemplateID=" & Form_frmSelectTemplate.TemplateID)
   strSubject = DLookup("Subject", "tblBodyTemplate", "TemplateID=" & Form_frmSelectTemplate.TemplateID)
   DoCmd.Close acForm, "frmSelectTemplate"
   strBody = strBody & ConvertBody(strBodyText)
   
   DoCmd.SendObject acReport, "actions and opps", "PDFFormat(*.pdf)", Me.[Connam Email], , , strSubject, strBody

Open in new window

Avatar of lehi52

ASKER

This code did not pull in the subject.
did you remove the report "actions and opps" or renamed it ?
Avatar of lehi52

ASKER

I renamed it.  to Action to do. But what if I wanted another option to also remove the attachment.
Like Scott McDaniel answered you in previous question https://www.experts-exchange.com/questions/28357659/Attach-a-PDF-that-was-attached-to-access-into-an-email.html
that if you want to attach other pdf's and not from your reports, then you should use the outlook object instate of using the sentopject.
Avatar of lehi52

ASKER

Gozreh,   I mean to just not include an attachment at all.  Sorry I wasnt clear on that.
Avatar of lehi52

ASKER

I tried to remove that line of code and the button click didn't work so I wasnt sure what I was doing wrong.

I guess this is another question which I can ask elsewhere if you prefer. Mainly here I would like to get the subject line inserting.
to send the report "Actions To Do" you can use this:
   DoCmd.SendObject acReport, "Actions To Do", acFormatPDF, Me.[Connam Email], , , strSubject, strBody

if you need to send email without report attached you should use this:
   DoCmd.SendObject acSendNoObject, , , Me.[Connam Email], , , strSubject, strBody

please check all option you can do with the SendObject method http://msdn.microsoft.com/en-us/library/office/ff197046.aspx

you can also see their on bottom of the page how to send email using outlook objects
Avatar of lehi52

ASKER

The subject line does merge now.  Gorzeh thank you.