Results 1 to 6 of 6
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Generate an email to all contacts

    Hi Guy's can the following code be changed to generate an email to all recipients, in the field i will have either a valid email address or Enter Email Address, the myExclude string does bypass anything that is Enter Email Address and goes to a record that has got a valid email address and opens x 1 email, I am looking to adapt it so a separate email is generated for each valid email address

    Code:
    Dim strEMail As StringDim oOutlook As Object
    Dim oMail As Object
    Dim strAddr As String, myExclude As String
    Dim MyDB As DAO.Database
    Dim rstEMail As DAO.Recordset
     
    Set oOutlook = CreateObject("Outlook.Application")
    Set oMail = oOutlook.CreateItem(0)
     myExclude = "Enter Email Address"
    Set MyDB = CurrentDb
    Set rstEMail = MyDB.OpenRecordset("Select * From tblCustomers WHERE InvoiceEmail <> '" & myExclude & "'", dbOpenSnapshot, dbOpenForwardOnly)
     
    With rstEMail
      Do While Not .EOF
        strEMail = rstEMail.Fields("InvoiceEmail") & ";"
          .MoveNext
      Loop
    End With
    
    
     
    With oMail
      .To = strEMail
      .Body = "Test E-Mail to Multiple Recipients"
      .Subject = "Test multiple emails"
        .Display
    End With
     
    Set oMail = Nothing
    Set oOutlook = Nothing
     
    rstEMail.Close
    Set rstEMail = Nothing


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Instead of building a multi-address To string, send email within loop of recordset.

    Very common topic and many examples.

    Code:
    With rstEMail
    Do While Not .EOF
       With oMail
         .To = rstEMail.Fields("InvoiceEmail")
         .Body = "Test single E-Mail to Multiple Recipients"
         .Subject = "Test multiple emails"
         .Display
       End With
       .MoveNext
    Loop
    End With
    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
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Thank you June7, i will try that, much appreciated

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    The only other question is that 1 of the emails opens in the taskbar, i would guess the last one in the recordset, how can i display within the loop so i can physically see all emails ?, i don't think.Display works after the loop ??

    Thank you

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Try this:

    MsgBox "Continue"
    .MoveNext
    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.

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Hi June7, perfect thank you

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

Similar Threads

  1. Replies: 1
    Last Post: 05-23-2018, 09:35 AM
  2. Auto email generate
    By nherbert31 in forum Queries
    Replies: 4
    Last Post: 08-01-2017, 12:38 PM
  3. Replies: 5
    Last Post: 03-23-2017, 06:38 AM
  4. Replies: 1
    Last Post: 04-09-2013, 06:59 AM
  5. Contacts Database and Email system
    By steve1978 in forum Access
    Replies: 1
    Last Post: 02-16-2011, 09:42 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