Results 1 to 6 of 6
  1. #1
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100

    Body Text in Access-generated emails.

    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

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    What exactly is
    "InputBox"
    That supposedly is the source of your Body????????????????????

  3. #3
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100
    Yes, I see. I have googled about and found the original source of the code which explains how to put the text in....looks like I have corrupted it along the way!

  4. #4
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    The problem is, you haven't got any code actually assigning anything to the mailitem's body.

  5. #5
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100
    Right you are. A similar looking code source from http://www.jephens.com/2007/05/13/ho...using-outlook/ quotes the following amendment
    Code:
    MyMail.Body = MyBodyText
    [
    I'll give it a try and see if it works.

  6. #6
    Mattbro is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    100
    Yes. If I include the following lines:
    Code:
       
    MyMail.Body = MyBodyText
    MyBodyText = "Enter text here"
    ....everything works. Job done! Thanks all.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-25-2013, 11:01 PM
  2. Replies: 7
    Last Post: 10-11-2012, 02:13 PM
  3. Replies: 1
    Last Post: 06-26-2012, 09:37 AM
  4. Getting table/form content into generated emails using VBA
    By Monterey_Manzer in forum Programming
    Replies: 5
    Last Post: 06-18-2012, 12:54 PM
  5. Generating emails with email-address in body
    By techexpressinc in forum Programming
    Replies: 1
    Last Post: 08-17-2011, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums