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

    command button to send e-mails based on query results

    Good Afternoon,

    I want to have a command button that when clicked it will send e-mails to all recipients based on a query results. When I click on the command button i get the following error:

    run time error 2295

    unknown message recipients; the message was not sent


    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: " & .Fields(2)

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

    End If


    .MoveNext
    Loop
    End With

    Set mydb = Nothing
    Set rsEmail = Nothing

    End Sub
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Have you step debugged? Does stoName get populated with valid data? See link at bottom of my post for guidelines on debugging techniques.
    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.

  3. #3
    Csalge is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    31
    I did and you were right. The stoname was not populated with valid data as I had the e-mail field formatted as hyperlink. I changed that to text and it works now.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-07-2012, 08:39 AM
  2. Send e-mails using Access
    By Dotty in forum Queries
    Replies: 4
    Last Post: 09-30-2011, 09:22 PM
  3. Use Query Results to send Email
    By Paul Ager in forum Programming
    Replies: 2
    Last Post: 05-05-2011, 09:57 AM
  4. Replies: 1
    Last Post: 01-20-2010, 12:54 PM
  5. Send multiple e-mails through Outlook based on query
    By dataphile in forum Programming
    Replies: 3
    Last Post: 12-30-2009, 12:04 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