Results 1 to 2 of 2

Thread: Emailing from Access to Outlook using Query and Mailto:

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,297
    Location
    Here is an example of the code you need from one of my databases

    Dim subject As String, Body As String, EmailAddress As String, sql As String
    Dim rs As Object, recount As Integer, count As Integer, swhere As String
    On Error GoTo errorcatch
    If Me.Extra = -1 Then ' you may not need this as it is a test to see if extra people are included
        sql = "SELECT emailExtraQuery.* " & _
        "FROM emailExtraQuery " & _
        "Where Xtra = -1" & _
        "And email = -1"
        Else
        If Me.Year <> "All" Then
            sql = "SELECT emailQuery.* " & _
            "FROM emailQuery " & _
            "Where RenewalYear = " & Me.Year & _
            "And email = -1"
        Else
            sql = "SELECT emailall.* " & _
            "FROM emailall " & _
            "Where email = -1"
        End If
    End If
    Set rs = CurrentDb.OpenRecordset(sql)
    'MsgBox rs.RecordCount
    If rs.RecordCount > 0 Then
    rs.MoveLast
    rs.MoveFirst
    'MsgBox rs.RecordCount
    recount = rs.RecordCount
    For count = 1 To recount
        If Not IsNull(rs![Home e-mail]) Then EmailAddress = EmailAddress & rs![Home e-mail] & ";"
        If Not IsNull(rs![Work e-mail]) Then EmailAddress = EmailAddress & rs![Work e-mail] & ";"
    rs.MoveNext
    Next count
    EmailAddress = Left(EmailAddress, Len(EmailAddress) - 1)
    'MsgBox EmailAddress
    DoCmd.SendObject , , , "if you want to send yourself a copy of the email put yor email address here", , EmailAddress, , , True
    End If
    rs.Close
    Set rs = Nothing
    Exit Sub
    errorcatch:
    MsgBox Err.Description
    Note the true on the end of the docmd.sendobject shows you the email address before trying to send anything.
    If you wish to compose the subject and body of the email prior to sending you can do so using a form to input them first as per the attached database.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •