Results 1 to 5 of 5
  1. #1
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46

    sending emails using VBA

    I want to trigger sending emails to multiple recipients, using a button on a form or report.



    Most of what I have read requires the purchase of mass emailing software (such as EASendMail or similar)

    Happy to get into some simple VBA programming, but am looking for some guidance or tutorials to get me underway.

    Also, can this be done under Outlook, and should I consider SMTP rather than POP settings ?

    Any help or advise would be appreciated.

    Stuart

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    when you say mass emailing, do you mean send multiple personalised emails - each to a singles address? or the same email to multiple recipients?

    if you look to the bottom of this thread you will see links to a number of other threads on the same subject

  3. #3
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46
    Ajax,

    Thanks for the pointers which seem like the way forward for me ...

    I have taken one of the codes which was reported as predominantly working, but it is falling over at the first hurdle with a compile error on "Dim objOutlook As Outlook.Application" "user-defined Type not defined". My overall code is as follows ....

    Code:
    Private Sub EmailAllBttn_Click()
    
    Dim MyDB As Database
    Dim MyRS As Recordset
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim TheAddress As String
    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset("BML Drivers")
    
    
    MyRS.MoveFirst
    
    
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
    Do Until MyRS.EOF
    ' Create the e-mail message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    
    TheAddress = MyRS![email 1]
    
    With objOutlookMsg
    ' Add the To recipients to the e-mail message.
    Set objOutlookRecip = .Recipients.Add(TheAddress)
    objOutlookRecip.Type = olTo
    
    ' Set the Subject, the Body
    .Subject = "subject"
    .Body = "test"
    
    ' Resolve the name of each Recipient.
    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    If Not objOutlookRecip.Resolve Then
    objOutlookMsg.Display
    End If
    Next
    .Display
    
    End With
    MyRS.MoveNext
    Loop
    
    
    
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    End If
    End Sub
    End Sub
    Any clues or help would be appreciated.

    Ta

    Stuart

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Add a reference to the Microsoft Outlook Object library
    OR change to using late binding code
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46
    That did it ~ Thanks for your help.

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

Similar Threads

  1. Sending emails using Office 365
    By aytee111 in forum Programming
    Replies: 4
    Last Post: 11-17-2015, 09:14 AM
  2. Sending out 2 emails with different attachments
    By Thompyt in forum Programming
    Replies: 6
    Last Post: 09-18-2015, 12:03 PM
  3. sending multiple emails wth vba
    By baronqueefington in forum Programming
    Replies: 2
    Last Post: 02-09-2015, 02:49 PM
  4. Sending multiple emails
    By Sephaerius in forum Database Design
    Replies: 4
    Last Post: 08-08-2013, 11:55 AM
  5. Sending multiple emails
    By Petefured in forum Programming
    Replies: 0
    Last Post: 05-24-2011, 03:40 AM

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
  •  
Other Forums: Microsoft Office Forums