Full Version: Email multiple reords to different addresses
UtterAccess Forums > Microsoft® Access > Access Forms
I have a continuous form where I select a record (using the record selector) and email the [Cust] & [Problem] fields to the email address in the [memail] field.
Here is the button code, which works fine.

Dim eTo As String, eCC As String, eSubject As String
Dim eCust As String, eMsg As String, eProblem As String
  If IsNull(Me.Memail) Or Me.Memail = "" Then
   MsgBox ("There is no email for this mechanic-message cancelled.")
    Exit Sub
    eTo = Me.Memail
    If IsNull(Me.Semail) Then
     eCC = ""
     eCC = Me.Semail
    End If
    eSubject = "Call ID: " & Me.Call_ID
    eCust = Me.Cust
    eProblem = Me.Problem
    eMsg = "Customer:" & vbCrLf & eCust
    eMsg = eMsg & vbCrLf & vbCrLf & "Problem:" & vbCrLf & eProblem
    DoCmd.SendObject , , , eTo, eCC, , eSubject, eMsg, True, ""
  End If

My problem now is that I want to select multiple records on the continuous form and automatically send the correct record information to each email address.
Can this be done?
I suggest:
- Include an extra field in the table called (for example) 'SendTo' , make it Boolean (Yes or No)
- Create a check box on the form in question and set its default to 'No' bind it to the above field
- Now you can choose which records you are going to send

for simplicity, create a query based on the table, include all the fields you need + 2 criteria:
SendTo = True (that gets all you have chosen)
Memail Not IsNull ( That will filter out the Non Emailaddys)

In code create a reccordset based on the above query
Loop through the recordset
- for each iteration of the loop, run the code you already have, but replace values from the Form with those from the recordset
- for each iteration of the loop set 'SendTo' to false (or you could run an update query
to set all to False when closing the form, then if the Send fails, you would still have the selection.)

You could also use a listbox to select the items but I think the above will give you more flexibility.

Do you mean there is no way to capture the records selected on the continuous form using the record selector?
lso, could you provide an example of the code that would loop through the recordset?
I am not a very good programmer! I usually copy code from the excellent UA examples and then modify it to fit my tables and fields.
Well, you can select more than one record with the r.selector but they have to be consecutive. I suppose that you could do something where when you click a record selector it is 'remembered' and added to a list but it wont show on the form and would become clumsy in any case.
Odont have much time til tonight maybe someone else can do you a Loop thru Recordset example or I will later. There may well be an example in the UA archive and there certainly will be via Google...look for a DAO recodrset when you find some examples.

Theres an example
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.