Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

E-mail code query - signature 1

Status
Not open for further replies.

PortyAL

Technical User
May 13, 2005
126
GB
Hi

I use the code below to create an e-mail from Access. The e-mail template contains a signature, but the strBody text inserted after the signature rather than before it. I know I can manually drag the text up before the signature, but is there a way of automatically putting it at the start of the e-mail?

Thanks

AL

Code:
Private Sub msqemail()

Dim appOutlook As Outlook.Application
Dim ItmNewEmail As Outlook.MailItem
Dim TemplateName As String
Dim strBody As String
Dim attnameDR As String
Dim attnameAP As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 'save record before proceeding

Rem TemplateName = "c:\Internal audit\E-mail templates\draft report e-mail.oft"
TemplateName = "i:\ia manual\e-mail templates\drtemp1.oft"
attnameDR = Forms![frm recs tracked jobs]![docfolder] & "\" & Forms![frm recs tracked jobs]![Job] & " MSQ.doc"


Set appOutlook = New Outlook.Application
Set ItmNewEmail = appOutlook.CreateItemFromTemplate(TemplateName)

strBody = strBody & Chr(13) & Chr(10)
strBody = strBody & Forms![frm recs tracked jobs]![ManagerFirstName] & Chr(13) & Chr(13)
strBody = strBody & "Further to the issue of the " & Forms![frm recs tracked jobs]!Job & " Final Report, please find attached a Management Satisfaction Questionnaire. The purpose of this is to allow you to give us your views on the service we provide and helps us to monitor the quality of our serivce. I'd be grateful if you could complete this questionnaire and return it to me as soon as possible." & Chr(13) & Chr(13)
strBody = strBody & "If you have any queries, please contact me." & Chr(13) & Chr(13)
strBody = strBody & "Thanks" & Chr(13) & Chr(13)

With ItmNewEmail
     .To = Forms("frm recs tracked jobs").Controls("contact").Value
     .Subject = Forms("frm recs tracked jobs").Controls("job").Value & " IA Inspection - Management Satisfaction Questionnaire"
     .Body = strBody
    .BodyFormat = olFormatHTML
    .Attachments.Add attnameDR
    .Display
    
End With

End Sub
 
Are you sure in your template that the signature is in the control that body uses? If not, rearrange the controls.

I ask because you explicitly set the body of the message to your string and therefore I would expect it to overwrite the entire body and not leave any of it.
 
Hi

The template was created from a blank e-mail which contained the signature.

Originally the code created a new e-mail item rather than from the template. This meant that no signature was shown. I then changed the code to create the e-mail from the template and the signature did show but was at the start of the e-mail rather than at the end.

I admit I'm not an expert in coding and am not sure how to check what you are asking.

Thanks

AL
 
All I am saying is that my expectation is that your template as the signature as part of the body and therefore when you set the body, I think it should wipe it out. The line I am talking about is below...

Code:
.Body = strBody



Try either using a msgbox or a debug.print to see what .body is before you set it...

I.e.

Code:
     .Subject = Forms("frm recs tracked jobs").Controls("job").Value & _ 
     " IA Inspection - Management Satisfaction Questionnaire"

    msgbox .Body 
    .Body = strBody

I could be wrong about this. If I am right you would see the signature in the body displayed in the message box or you may get an error because it is null. In which case we'll have to do something clever to get the signature.
 

Tried the above and the signature does indeed appear in the message box.

AL
 
Ok...


Change

Code:
msgbox .Body

To

Code:
msgbox strbody

You should see the text you are setting .body to exactly. I am thinking strbody must contain the signature at this point. If so, that raises the question, where are you grabbing it? If this is the case you may have to add a watch to strbody. Or just set it to a zero length string after the Dim statemtns to initialize it...

Code:
strbody = ""

If I am wrong then I'll have to rack my brain for a minute.
 
Hi

When I use "msgbox strbody" as above the text of the message appears in the message box, but the signature does not.

Thanks for your help so far. It would probably be just as easy for me to just the drag the message text above the signature in the e-mail, but I was just curious as to why the signature came before the text.

AL
 
Not at all the behavior I would have expected.

It sounds like the body field in the template is part of whatever is equivalent to Access's control source.

My advice is to play with making templates until you get it to work...

The first thing I would do is to open the base template, put my cursor in the body and hit end and cursor down and right cursor a bunch of times and finally paste in the signature and hope for the best.

I wish I knew more about the nuances of Outlook. I'd be curious to hear what works as I am sure anyone searching later will.
 
Thanks for your help.

I'll play about with the code and the template and report back if I make progress.

AL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top