Results 1 to 7 of 7
  1. #1
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74

    SendObject and No Email Address

    Hi All,

    I have a Command Button on a Form that when executed will open my Outlook and add the email addresses of records assiciated with an ID Code field. This works great with multiple email addresses when the ID code if filtered. I posted the code behind the Command Button below.

    Problem: If one of the filtered records does not have an email address I get the following message "Unknown message recipient(s); the message was not sent."

    Is there something in the code I can change to ignore records without an email address?

    Your help is much appreciated!!

    Tommy




    Private Sub EMAIL_DRIVERS_Click()
    DoCmd.RefreshRecord
    Dim strSQL As String
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strEmailAddy As String
    Set db = CurrentDb()
    'following would be an SQL statement that retrieved the appropriate records. You could also use a query directly

    '
    strSQL = "SELECT * FROM [KT VANPOOL DRIVER RECORDS] WHERE [ID CODE] = """ & Forms![KITSAP TRANSIT DRIVERS].[ID CODE] & """"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    Do While Not rs.EOF


    strEmailAddy = strEmailAddy & rs![E-MAIL ADDRESS] & ";"
    rs.MoveNext
    Loop
    Set rs = Nothing
    Set db = Nothing

    On Error GoTo Err_cmdOpenEmail_Click
    DoCmd.SendObject acSendNoObject, , , strEmailAddy, , , , , True

    Exit_cmdOpenEmail_Click:
    Exit Sub
    Err_cmdOpenEmail_Click:
    If Err.Number = 2501 Then
    Resume Next
    Else
    MsgBox Err.Description
    Resume Exit_cmdOpenEmail_Click
    End If

    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'd add to the WHERE clause in your SQL:

    "...AND [E-MAIL ADDRESS] Is Not Null"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74

    RE: SendObject and No Email Address

    Is this how I would do it:

    strSQL = "SELECT * FROM [KT VANPOOL DRIVER RECORDS] WHERE [ID CODE] = """ & Forms![KITSAP TRANSIT DRIVERS].[ID CODE] & """"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    Do While Not rs.EOF
    strEmailAddy = strEmailAddy & rs![E-MAIL ADDRESS] & [E-MAIL ADDRESS] Is Not Null" ";"


    Thanks for your help!

    Tommy

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No, I said add to your SQL string:

    strSQL = "SELECT * FROM [KT VANPOOL DRIVER RECORDS] WHERE [ID CODE] = '" & Forms![KITSAP TRANSIT DRIVERS].[ID CODE] & "' AND [E-MAIL ADDRESS] Is Not Null"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74

    RE: SendObject and No Email Address

    That did it!

    Thanks again for the outstanding service you've given me. I owe you an espresso the next time you are in the Seattle area!!

    Tommy

  6. #6
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74
    That did it!

    Thanks again for the outstanding [I meant service] you've given me. I owe you an espresso the next time you are in the Seattle area!!

    Tommy

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help. Might get up there in Feb for a Microsoft thing, so I may take you up on that!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Multiple Email Address
    By Tomfernandez1 in forum Forms
    Replies: 15
    Last Post: 09-15-2011, 01:52 PM
  2. Generating emails with email-address in body
    By techexpressinc in forum Programming
    Replies: 1
    Last Post: 08-17-2011, 01:48 PM
  3. Passing Email Address Into Outlook
    By cg1465 in forum Access
    Replies: 1
    Last Post: 10-01-2010, 07:59 AM
  4. Email sent via DoCmd.SendObject
    By silverback in forum Programming
    Replies: 0
    Last Post: 10-29-2009, 06:26 AM
  5. Send email using SendObject instruction
    By stecco in forum Access
    Replies: 4
    Last Post: 09-09-2009, 01:55 AM

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