Results 1 to 2 of 2
  1. #1
    EHittner is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2009
    Posts
    32

    Automatically E-Mail to an E-Mail List in a Table

    I already know about the "EmailDatabaseObject" macro action. I've used it to automatically e-mail to a list specified in the properties.



    But what I'd like to do is, using a table with a list of people and their e-mails, build a macro item that automatically e-mails to the people in that table. I can build a form for my users to manipulate the list of people and their e-mail. But I want the macro to pull the e-mails from that table.

    I realize that this will involve code -- but my code skills aren't quite up to speed yet. Anyone know where I can go to get the information I need to build this function?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make a form, with a listbox , lstEmails. (connect the list to the mail list table)
    put a list box/or combo to select a report
    put a button to scan the list of emails to send the chosen report

    The button would execute : ScanAndEmail in the button ON CLICK event

    Code:
    '------------
    Public Sub ScanAndEmail()
    '------------
    Dim vTo, vSubj, vBody, vRpt
    Dim vFilePath
    dim i as integer
    
    
    For i = 0 To lstEAddrs.ListCount - 1
       vRpt = lstEAddrs.ItemData(i)
       lstEAddrs = vRpt
       vTo = lstEAddrs.Column(2)
       
       vBody = "body of email"
       vSubj = vRpt
       vFilePath = ""  'path of the snapshot or XL or PdF
       
       Call Email1(vTo, vSubj, vBody, vFilePath)
    Next
    End Sub
    
    
    
    
    '-------
    'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!!   checkmark OUTLOOK OBJECT LIBRARY in the vbE menu, Tools, References
    '-------
    Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody,optional ByVal pvFile) As Boolean
    Dim oApp As Outlook.Application
    Dim oMail As Outlook.MailItem
    
    
    On Error GoTo ErrMail
    
    
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(olMailItem)
    
    vRpt = forms!frmRpts!cboRpt
    
    With oMail
        .To = pvTo
        .Subject = pvSubj
        .Body = pvBody
    
       'USE THIS FOR SENDING THE REPORT IN THE BOX
       DoCmd.SendObject acSendReport, vRpt, acFormatPDF, pvTO, , , pvSubj, pvBody
    
    
    
       'USE THIS FOR ATTACHEMENTS  
      If Not Ismissing(pvFile) Then  .Attachments.Add pvFile, olByValue, 1
        
    .Send
    End With
    
    
    EmailO = True
    Set oMail = Nothing
    Set oApp = Nothing
    Exit Function
    
    
    ErrMail:
    MsgBox Err.Description, vbCritical, Err
    Resume Next
    End Function

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

Similar Threads

  1. Replies: 2
    Last Post: 12-13-2013, 03:13 PM
  2. Replies: 3
    Last Post: 02-18-2013, 09:05 AM
  3. Replies: 1
    Last Post: 09-14-2012, 10:27 AM
  4. Automatically Send E-Mail from Access
    By lilygtg in forum Access
    Replies: 1
    Last Post: 08-24-2011, 05:48 PM
  5. Sending mail automatically
    By carstenhdk in forum Forms
    Replies: 1
    Last Post: 05-31-2010, 04:23 PM

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