Results 1 to 2 of 2
  1. #1
    Csalge is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    31

    Send automatic e-mail

    Hi,



    I have a form with a command button that when pressed it's supposed to e-mail all individuals based on a query result. Here's my code:
    Private Sub Command92_Click()

    Dim mydb As DAO.Database
    Dim rsEmail As DAO.Recordset
    Dim stoName As String
    Dim sSubject As String
    Dim smessagebody As String
    Set mydb = CurrentDb()
    Set rsEmail = mydb.OpenRecordset("qryexcludednoemail", dbOpenSnapshot)
    With rsEmail
    .MoveFirst
    Do Until rsEmail.EOF
    If IsNull(.Fields(0)) = False Then
    stoName = .Fields(0)
    sSubject = "Excluded time requested for: " & .Fields(2)
    smessagebody = "The following excluded time requested: " & vbCrLf & _
    "Type Requested: " & .Fields(3) & vbCrLf & _
    "Notes with Excluded Time Requested: " & .Fields(4) & vbCrLf & _
    "Reason for Denial: " & .Fields(5)

    DoCmd.SendObject acSendNoObject, , , stoName, , , sSubject, smessagebody, False, False

    End If


    .MoveNext
    Loop
    End With

    Set mydb = Nothing
    Set rsEmail = Nothing


    It works but I have two problems. For my message body I would like for each field to be on a separate line in the body of my email. I'm not sure how to do that. Right now all the text is all together. My second problem is that one of the fields in my query is based on a combo box and my e-mail message shows the ID field instead of the text field associated with it (as displayed in my query).

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,958
    If the vbCrLf is ignored then probably need to use Outlook object VBA code. Example:
    Code:
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
        .BodyFormat = olFormatRichText
        .To = "email address here"
        ''.cc = ""
        ''.bcc = ""
        .Subject = "subject here"
        .HTMLBody = "<HTML><BODY>some text here <br>more text here</body></html>"
        '.Attachments.add ()
        .DeleteAfterSubmit = True 'to not save in sent bin
        ''.Display
        .Send
    End With
    The olFormatRichText might be enough to cause recognition of vbCrLf. If not, then need to use HTML formatted body with HTML code tags. Or maybe both are needed, can't remember why I have both lines in code.

    Is the field in the query the field from table that is storing the ID and it has a lookup for displaying the text? This is one reason not to build Lookups in tables, can't see the real value and is misleading. Need to retrieve the text field by joining tables.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-14-2012, 10:27 AM
  2. Send multiple mail
    By john_gringo in forum Access
    Replies: 1
    Last Post: 06-09-2012, 05:21 PM
  3. Send E-Mail 2010
    By lrobbo314 in forum Access
    Replies: 6
    Last Post: 03-22-2012, 11:49 AM
  4. send a form via mail
    By Fabdav in forum Forms
    Replies: 1
    Last Post: 10-12-2011, 07:35 AM
  5. Send mail to the chosen ones
    By carstenhdk in forum Import/Export Data
    Replies: 0
    Last Post: 05-18-2010, 11:51 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