Link to home
Start Free TrialLog in
Avatar of seanlhall
seanlhallFlag for United States of America

asked on

How can I send an email using send object containing multiple records?

How can I send an email using send object containing multiple records in MS Access?  Currnetly I can send an email using sendobject. I would like to include records from a subform how and where would I do that.
ASKER CERTIFIED SOLUTION
Avatar of Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you mean you want the addressee to receive only the data from the subform and not the main form?  To my knowledge that cannot be done.  Remember a subform is not really a form but rather a control and all controls on a form are included in the attachment when the form is Emailed.
Avatar of seanlhall

ASKER

I worded it wrong I want to include records from a related table. How do I get all related records in the email?
Just as you can send a Table as an attachment in half a dozen formats, including html and rtf, so can you send a query containing info from several tables - if that's what you meant by 'I want to include records from a related table.'
Not as an attachment but in the email body.
Here is what I was working on. The problem I am having is it only puts in one record I need every recrod put in the body of the email.
Private Sub EmailUpdates_Click()
Dim objOL As New Outlook.Application
Dim objOLMail As Outlook.MailItem
Dim Empname As String
Dim empemail As String
Dim db As Database
Dim rcd As Recordset
Dim SQLUpdate As String, Updatetext As String
empemail = "email here"
Set db = Currentdb()
SQLUpdate = "SELECT tblupdatetable.caseupdate FROM tblupdatetable"

Set rcd = db.OpenRecordset(SQLUpdate, dbOpenSnapshot)

With rcd
      .MoveFirst
      Do Until rcd.EOF
            Updatetext = .Fields(0)
            .MoveNext
      Loop
End With
strBody = Updatetext
    Set objOLMail = objOL.CreateItem(olMailItem)
    With objOLMail
        .To = empemail
        '.cc =
        .subject = Nz(strSubject, "")
        .Body = Nz(strBody, "")
        If Nz(strpath, "") <> "" Then
            .Attachments.Add strpath
        End If
        .display
    End With
Exit_EmailUpdates:
      Set db = Nothing
      Set rcd = Nothing
      Exit Sub
End Sub

Open in new window

I fiqured it out.
Private Sub EmailUpdates_Click()
Dim objOL As New Outlook.Application
Dim objOLMail As Outlook.MailItem
Dim Empname As String
Dim empemail As String
Dim db As Database
Dim rcd As Recordset
Dim SQLUpdate As String, Updatetext As String
empemail = "email here"
Set db = Currentdb()
SQLUpdate = "SELECT tblupdatetable.date, tblupdatetable.caseupdate FROM tblupdatetable"

Set rcd = db.OpenRecordset(SQLUpdate, dbOpenSnapshot)

With rcd
      .MoveFirst
      Do Until rcd.EOF
            strBody = strBody & .Fields(0) & vbCrLf & .Fields(1) & vbCrLf & vbCrLf & "Update" & vbCrLf
            .MoveNext
      Loop
End With
    Set objOLMail = objOL.CreateItem(olMailItem)
    With objOLMail
        .To = empemail
        '.cc =
        .subject = Nz(strSubject, "")
        .Body = Nz(strBody, "")
        If Nz(strpath, "") <> "" Then
            .Attachments.Add strpath
        End If
        .display
    End With
Exit_EmailUpdates:
      Set db = Nothing
      Set rcd = Nothing
      Exit Sub
End Sub

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial