Email Report In Message Part, NOT as a attachment

Parra

Well-known Member
Joined
Feb 21, 2002
Messages
752
Hi I would like to email a report, not as an object, but in the message portion of an email.

This is the code I have right now. The report name is "Qry Email FiberSat"

Dim stDocName As String
stDocName = "Qry Email FiberSat"
DoCmd.SendObject acReport, stDocName,

Can someone help me out?

I am using
Access 2000 and Outlook.

Thank you
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I used the on close event of the report to pick up the message from the report but you can do what ever suits your needs to get it.


Option Compare Database

Dim message As String



Public Sub sendreport()
On Error GoTo Send_report_Err




DoCmd.SendObject acSendNoObject, "Qry Email FiberSat", "", "", "", "", "test subjest", message, True, ""

Send_report_Exit:
Exit Sub

Send_report_Err:
MsgBox Error$
Resume Send_report_Exit

End Sub



Public Sub getmessage()

'on close event from report sent here to pass variable

message = Reports![Qry Email FiberSat]!ReportField

End Sub


I tried it out and it works, I'm sure there are different methods.


Ziggy
 
Upvote 0
Parra,

This code works on a similar principle to the sending an Excel range through Outlook here.. Take a look and let me know how you get on. PLEASE NOTE! Before this code will work you'll need to click Tools, References from within the VB Editor and choose Microsoft Scripting Runtime and Microsoft Outlook n.x Object Library.

Code:
Sub SendReport()
    Dim olApp As Outlook.Application, olMailitem As Outlook.MailItem
    Dim FSTextStream As Scripting.TextStream, FSObj As Scripting.FileSystemObject
    Dim strHTMLFile As String


    'Name of the temporary data file used to store the
    'report in HTML format - change as desired
    strHTMLFile = "C:\temp\rpt.html"


    'Output the report in HTML format
    DoCmd.OutputTo acOutputReport, "rptConsolidationReport", acFormatHTML, strHTMLFile



    'Open the text file that we've just created
    Set FSObj = CreateObject("Scripting.FilesystemObject")
    Set FSTextStream = FSObj.OpenTextFile(strHTMLFile, ForReading)


    'Create an Outlook message and set its HTMLBody property to what we created above
    Set olApp = New Outlook.Application
    Set olMailitem = olApp.CreateItem(0)

    With olMailitem
        .HTMLBody = FSTextStream.ReadAll

        'You can set all sorts of properties of your email e.g.
        .Subject = "Hello, check out this report"
        .To = "dan@danielklann.com"
        .Importance = olImportanceHigh

        'Use .Send to send the email automatically, or .Display to show it
        olMailitem.Display

    End With


    'Clear up
    Set FSTextStream = Nothing: Set FSObj = Nothing

End Sub
 
Upvote 0
DK, I am glad you replied to my message.

I am not a pro at VBA, I usually record macros and modify them as needed.

I hope you will be around to answer questions, if I can't get this thing to work.

Thanks
Parra
 
Upvote 0

Forum statistics

Threads
1,221,544
Messages
6,160,431
Members
451,646
Latest member
mmix803

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top