Table data in email body

LB79

Registered User.
Local time
Today, 20:46
Joined
Oct 26, 2007
Messages
505
Hello,

I have a function that creates an email in Outlook with subject, body, To, etc.
In the body of the email I want to include the data from 1 column of a table (about 10 records).

How can I go about doing this? Can I store the table data as a VB variable?

Thanks for any help J
 
Hello,

I have a function that creates an email in Outlook with subject, body, To, etc.
In the body of the email I want to include the data from 1 column of a table (about 10 records).

How can I go about doing this? Can I store the table data as a VB variable?

Thanks for any help J inn

just from friendly advice...what I've done in the past, is use the properties of the mailitem object to get what I want. if you're familiar with this, you probably already know that the <body> tag of an outlook message has an innerHTML attribute assigned to it. if i were experimenting with this, i would seriously do this:
PHP:
with olmailitem
.bodyinnerHTML = "<table><tr>Column Name Here</tr>"

while not rs.eof
  .bodyinnerHTML = .bodyinnerHTML & "<td>" & rs!yourField & "</td>
     rs.movenext
wend

.bodyinnerHTML = .bodyinnerHTML = .bodyinnerHTML & "</table>"
that's psuedocode, as i haven't done it for a while, but it should get thyou through, OK?
 
Hello,

Thanks for the advice… although I don’t really understand what to do with it (I cant see some of the commands like bodyinnerhtml in VBA).

My line of thinking (which may be very wrong), was something like this:

DoCmd.TransferDatabase acExport, MyData, "MyQuery", DataOnly, False

So the command would export the MyQuery data to the MyData variable, which I can then use in the email body.
Is something like that possible?

Thanks
 
Hello,

Thanks for the advice… although I don’t really understand what to do with it (I cant see some of the commands like bodyinnerhtml in VBA).

My line of thinking (which may be very wrong), was something like this:



So the command would export the MyQuery data to the MyData variable, which I can then use in the email body.
Is something like that possible?

Thanks

i'll make you a deal LB.....upload your database here...and I'll do it for you. or show you what I mean rather. keep in mind through, that i have access to ol 2003 only right at this moment, but I'll show you exactly what I mean. do that for me, and I'll show you want you (hopefully) want to see.
 
There might be something in here that you could adjust to help you;
Code:
Private Sub cmdEmail_Click()
On Error GoTo ErrHandler
Dim rsEmail As DAO.Recordset
Dim oItem As Outlook.MailItem
Dim Datarange As Recipients
Dim oOutlookApp As Outlook.Application
Dim oDoc As Word.Application
Dim objInsp As Outlook.Inspector
Dim strMessage
    If IsNull(Me.fPath) Or IsNull(Me.selLetter) Then
        MsgBox "Both documents are required for the E-mail mailing.", vbOKOnly, "Both Required"
        Exit Sub
    Else
        DoCmd.SetWarnings False
        Kill "c:\Export\MergeEmail.xls"
        DoCmd.OpenQuery "qryDM-Export-Cases-Email", acViewNormal
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "LL-MergeEmail", "c:\Export\MergeEmail.xls"
    End If
    message = "Enter the subject to be used for each e-mail message."
    Title = "Email Subject"
    mysubject = InputBox(message, Title)
    If mysubject = "" Then
        MsgBox "You cancelled the process, or subject not completed.", vbInformation + vbOKOnly, "Information"
        Exit Sub
    End If
    
Set oOutlookApp = GetObject(, "Outlook.Application")
    
DoCmd.Hourglass True
Set oDoc = CreateObject("Word.Application")
    oDoc.Documents.Open ("C:\Export\" & Me.selLetter.Value & ".doc")
Set rsEmail = CurrentDb.OpenRecordset("ll-mergeEmail")
Do While Not rsEmail.EOF
    oDoc.ActiveDocument.MailMerge.Check
        If IsNull(oDoc.ActiveDocument.MailMerge) Then
            GoTo MergeError
        End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
    strMessage = oDoc.ActiveDocument.Content
        
    With oItem
        .Subject = mysubject
        .Body = strMessage
        .To = rsEmail.Fields("[Email Addr]").Value
        .Attachments.Add Me.fPath.Value, olByValue, 1, mysubject & "Attachment"
        .Display
    End With
rsEmail.MoveNext
oDoc.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
oDoc.ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Loop
oDoc.Documents.Close (False)
oDoc.Application.Quit (False)
Set rsEmail = Nothing
Set oLetter = Nothing
Set oDoc = Nothing
Set oItem = Nothing
DoCmd.Hourglass False
DoCmd.OpenForm "frmDM-Contact-History"
Exit Sub
ErrHandler:
DoCmd.Hourglass False
    If Err.Number = 5174 Then
        MsgBox "File selected could not be found.", vbOKOnly, "File Error"
    Else
    If Err.Number = 4198 Then
        oDoc.Quit (False)
        MsgBox "You cancelled the opening of the document.", vbOKOnly, "User Cancelled"
    End If
    If Err.Number = 4605 Then
        MsgBox "You have selected an Email template which is not a merge document." & Chr(13) & Chr(10) & _
        "Please check and try again.", vbExclamation + vbOKOnly, "No Merge Fields"
        oDoc.Documents.Close (False)
        oDoc.Application.Quit (False)
        Set rsEmail = Nothing
        Set oLetter = Nothing
        Set oDoc = Nothing
        Set oItem = Nothing
        DoCmd.Hourglass False
    End If
    End If
Exit Sub
        
MergeError:
    If Err.Number = 4605 Then
        MsgBox "You cancelled the process.", vbOKOnly, "User Cancelled"
        oDoc.Documents.Close (False)
        oDoc.Application.Quit (False)
        Set rsEmail = Nothing
        Set oLetter = Nothing
        Set oDoc = Nothing
        Set oItem = Nothing
        DoCmd.Hourglass False
    Else
    If Err.Number = 53 Then
        Resume Next
    End If
    End If
oDoc.Documents.Close (False)
oDoc.Application.Quit (False)
Set rsEmail = Nothing
Set oLetter = Nothing
Set oDoc = Nothing
Set oItem = Nothing
DoCmd.Hourglass False
End Sub
 
Hi,

Thanks for your offer – that’s really kind.
I'm sure you’ll understand that I cant send the database due to company policy etc etc, so I’ve put together a quick mdb with cut down examples of what I need.

The cmd button on the for creates an email. I need for the email body to include the data from Table1.

Thanks again for your help J
 

Attachments

Users who are viewing this thread

Back
Top Bottom