Hi All,
I have databases which from an on-click event, will generate emails-(can't recollect where the code came from, but it's on the net somewhere). It has worked fantastically for me in a number of applications. The method has a module with the following code:
Code:
Option Compare Database
Option Explicit
Public Function SendEMail()
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim stDocName As String
Set fso = New FileSystemObject
Subjectline$ = "Yada yada yada"
MyBodyText = "Blah Blah Blah Blah Blah"
If 1 = 2 Then
BodyFile$ = "InputBox"
Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)
MyBodyText = MyBody.ReadAll
MyBody.Close
End If
Set MyOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("MyEmailAddresses")
Dim MyRecip As Outlook.Recipient
Do Until MailList.EOF
Set MyMail = MyOutlook.CreateItem(olMailItem)
'MyMail.To = MailList("email")
Set MyRecip = MyMail.Recipients.Add(MailList("email"))
MyRecip.Type = olBCC
MyMail.Subject = Subjectline$
MyMail.Attachments.Add "C:\My Documents\Report.rtf", olByValue, 1, "My Displayname"
Dim MyQuery As QueryDef
Set MyQuery = CurrentDb.QueryDefs("ReportSource")
MyQuery.SQL = "select * from emails "
MyQuery.Close
MyMail.Send
MailList.MoveNext
Loop
Set MyMail = Nothing
MyOutlook.Quit
Set MyOutlook = Nothing
MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing
End Function
.
The problem I am having is that in it's current application, the 'MyBodyText' for the email will not appear in the email. I can't see why not. Subject line works fine. Can anyone see what the problem is? Using outlook 2010 on XP/7.
Many thanks,
Mattbro