[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send Access report in Outlook Message Body.

Posted on 2006-05-05
7
Medium Priority
?
874 Views
Last Modified: 2012-06-27

Hello, I am sending an emai message from Access 2003 with an html attachment. (Its a report that was just exported to html).  I would like to include the (report) in the body of the message. Not just an attachment.  it could be rtf, htm or whatever, just as long as the report in inthe body.  The report is not very long. Any help would be greatly appreciated.  Thanks!


  Dim objOutlook As Outlook.Application
  Dim objOutlookMsg As Outlook.MailItem
  Dim objOutlookRecip As Outlook.Recipient
  Dim objOutlookAttach As Outlook.Attachment

  objOutlookAttach = C:\myfile.htm

    Set objOutlook = CreateObject("Outlook.Application")

    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    Set objOutlookRecip = objOutlookMsg.Recipients.Add(TheAddress)
    objOutlookRecip.Type = olTo

    objOutlookMsg.Subject = (Subject)
    objOutlookMsg.BodyFormat = olFormatHTML
    objOutlookMsg.Body = (MessageBody)   '  Here I want to add the contents of myfile.htm  
    objOutlookMsg.Attachments = AttachmentPath
0
Comment
Question by:sourcelink
  • 3
5 Comments
 
LVL 11

Expert Comment

by:EMCIT
ID: 16617221
Can you reference the text from a field in your form?

 objOutlookMsg.Body = Forms!FormName!TextBoxName
0
 
LVL 8

Accepted Solution

by:
Pigster14 earned 1000 total points
ID: 16617915
Use the recordsource behind your report.

Loop through it in your e-mail code and you can write whatever fields out that you want. You may have to play with the way it formats in the message. What I would do is just load the data into one variable and then make the message equal to that variable.

So say:

2005     10     Mickey Mouse
2006     11     Minnie Mouse

(Example of report data)

Then when you get the first record.

variable = !Year & " " & !Num & " " & !Name & Chr(13) & variable

Then the second record comes into the same line and it will add a carriage return after each record.

The loop would be

Dim rs as recordset
Dim varStr as string

varStr = ""
Set rs = currentdb.openrecordset("recordsourcetable")

With rs
.MoveFirst
Do Until .eof
    varStr = !Year & " " & !Num & " " & !Name & Chr(13) & variable
    .MoveNext
Loop
End With

Make varStr = to the message part you send out.

Thanks.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16619278
So is this just an three part process?

1) Save your report as an html output file.
2) Open the file and grab the source text.
3) Insert the source text into your Outlook email object.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16619294
Of course Pigster's solution is also viable (you could elaborate on it with a few well chosen html tags to format it when inserted into your email.)
I did an example of that type of thing here on EE once... damn I can never remember where... umm...
I'll have a look.
0
 
LVL 44

Assisted Solution

by:Leigh Purvis
Leigh Purvis earned 1000 total points
ID: 16619300
Gotcha.
http://www.experts-exchange.com/Databases/MS_Access/Q_21630696.html

Probably just the final suggestion towards the bottom worth having a peek at.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question