Send Query Results as E-mail Body

andrewbecks

New Member
Joined
May 23, 2008
Messages
2
Good afternoon.

I have an Access 2003 database and in it, there is a query called Mobile View. I'd like to send the results of the query in a e-mail as the body of the e-mail (not as an attachment).

Below is the module that I'm trying to use. The problem is that when the module gets to the Dim MyItem As Outlook.MailItem line, it returns the following error: "Compile error: User-defined type not defined".

Can someone please help me figure out the issue?

Thank you so much in advance.

Rich (BB code):
Sub RTFBodyX()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Dim RTFBody, strTo
Dim MyItem As Outlook.MailItem
Dim MyApp As New Outlook.Application
DoCmd.OutputTo acOutputQuery, "Mobile View", acFormatHTML, "Mobile View.htm"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("Mobile View.htm", ForReading)
RTFBody = f.ReadAll
'Debug.Print RTFBody
f.Close
Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
   .To = "abecks@rubytuesday.com"
   .Subject = "txtSubjectLine"
   .HTMLBody = RTFBody
End With
MyItem.Display
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You need to set a reference to the Outlook reference library via Tools>References... in the VBE.
 
Upvote 0
Hi
is there any option to mark email address dynamically, i mean the email address get from query it self
 
Upvote 0
Include the email address table field in your query; change the .To line so as to refer to the query field name.
Methinks you'd be better off starting your own thread instead of tagging on to a 14 year old one?
 
Upvote 0
Include the email address table field in your query; change the .To line so as to refer to the query field name.
Methinks you'd be better off starting your own thread instead of tagging on to a 14 year old one?
@atuljadhavnetafim has already done that, plus crossposted over on AF
 
Upvote 0

Forum statistics

Threads
1,221,517
Messages
6,160,260
Members
451,635
Latest member
nithchun

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