# MS-Access Emailing Multiple Recipients



## hedikye (Dec 5, 2010)

I am using a form to display a continuous number of records. Each record gets emailed to a different person. When I try to use the code to email the record, only the first one is sent. Does anyone have any script where I can send the entire table?


----------



## AlbertMC2 (Jul 15, 2010)

Hi

1. Can you paste the code you are trying to use?
2. Does each record have an email address as one of the fields to which that record must be emailed?

Am I correct in saying that you want a procedure that runs through a whole table / query, reading each record and sending that record to an email address which is also one of the fields in that record?


----------



## AlbertMC2 (Jul 15, 2010)

hedikye said:


> Your assumptions are exactly right. I am reading a table where each record has a separate email address. I am trying to output the entire table and have each individual record transmitted to the associated account.


Please keep all communication in the forums.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

See the attached file for the example.

I have created a:
Table = *tblA* with all the persons details including a field labeled *Email* with their email address.
Query = *qryA*. This is just a query that gets updated dynamically depending on the person's email address.
Report = *rptA*. The report is based on qryA. It is also what the document will look like that is emailed to the person.
Form = *frmA* that displays all the records with their details. It also contains a button which when pressed sends each record to its appropriate email address.
The button goes through the records on the form. 
For each record it:
- updates qryA by filtering the query and only displaying that particular record in question.
- Because qryA is updated rptA is automatically updated.
- The report is sent to the email address in the field "Email"
-Once done the form is refreshed

The button code:

```
Dim stDocName As String
    Dim sqlStatement As String
    Dim rst As DAO.Recordset
    Dim dbs As DAO.Database
    Dim RecSourceTemp As String
        
    Set dbs = CurrentDb()
    Set rst = Me.Recordset
    
    RecSourceTemp = Me.RecordSource
    
    Do While Not rst.EOF
        sqlStatement = "SELECT tblA.ID, tblA.Name, tblA.Surname, tblA.Address, tblA.Note, tblA.Email FROM tblA WHERE ID=" & rst![ID] & ";"
        CurrentDb.QueryDefs("qryA").SQL = sqlStatement
        DoCmd.SendObject acReport, "rptA", acFormatHTML, rst![Email], , , "Test Email Subject", , False
        rst.MoveNext
    Loop
    
    rst.Close
    dbs.Close
    
    Me.RecordSource = RecSourceTemp
    Me.Requery
```
For more info on the SendObject method see: DoCmd SendObject Command in Microsoft Access: Features and Limitations for Sending Emails

Let us know how it goes or if you need any more help or explanations.


----------

