I have searched everywhere on the net for the answer to my question and I found a post on this forum: Sending a report by mail. But even in the post there was no solution.
I would like to send a report that I have created in access 2003 in an e-mail not as an attachment, but in the body. I can't find the code to publish my report to word from Access. Here is what I have. Any help is greatly appriciated as I fear I am in over my knowledge level. The code below is what I have found from different examples.
Sub MakeEmail()
Dim objOutlook As Outlook.Application
'Dim objOutlookExp As Object
Dim objDrafts As Object
Dim objEmail As Object
Dim strBody, strTitle, strTo As String
Dim Doc As Word.Document
Dim objAccess As Access.Application
Dim Rpt As Access.Report
Set objOutlook = New Outlook.Application
Set Doc = objOutlook.ActiveInspector.wordeditor
' Open the outlook drafts folder
Set objDrafts = objOutlook.Session.GetDefaultFolder(olFolderDrafts)
If objDrafts = "Drafts" Then
' Create new email in Drafts folder
Set objEmail = objDrafts.Items.Add
Set Doc = objEmail.getinspector.wordeditor
Set wdParg = Doc.Paragraphs
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Need to know how to Publish from Access to word in VBA Code
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Copy the published Report
Doc.Selection.WholeStory
Doc.Selection.Copy
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
strBody = "This is where I need to paste Wholestory, maybe using a"
DataObject.GetFromClipboard ""
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
strTitle = "Access to Outlook Test"
objEmail.To = strTo '-an e-mail address
objEmail.Body.printtext Text:="Report for today:"
objEmail.Body.printparagraph
wdParg.Paste 'to paste my report
objEmail.Body.printparagraph
objEmail.Body.printtext Text:="If any problems call"
objEmail.Body.printparagraph
objEmail.Body = strBody
objEmail.Subject = strTitle
Set objDoc = objEmail.Attachments
objDoc.Add strAttach
' Save email in drafts folder
objEmail.Close olSave
Else
MsgBox "No Drafts Folder"
End If
End Sub
I would like to send a report that I have created in access 2003 in an e-mail not as an attachment, but in the body. I can't find the code to publish my report to word from Access. Here is what I have. Any help is greatly appriciated as I fear I am in over my knowledge level. The code below is what I have found from different examples.
Sub MakeEmail()
Dim objOutlook As Outlook.Application
'Dim objOutlookExp As Object
Dim objDrafts As Object
Dim objEmail As Object
Dim strBody, strTitle, strTo As String
Dim Doc As Word.Document
Dim objAccess As Access.Application
Dim Rpt As Access.Report
Set objOutlook = New Outlook.Application
Set Doc = objOutlook.ActiveInspector.wordeditor
' Open the outlook drafts folder
Set objDrafts = objOutlook.Session.GetDefaultFolder(olFolderDrafts)
If objDrafts = "Drafts" Then
' Create new email in Drafts folder
Set objEmail = objDrafts.Items.Add
Set Doc = objEmail.getinspector.wordeditor
Set wdParg = Doc.Paragraphs
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Need to know how to Publish from Access to word in VBA Code
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Copy the published Report
Doc.Selection.WholeStory
Doc.Selection.Copy
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
strBody = "This is where I need to paste Wholestory, maybe using a"
DataObject.GetFromClipboard ""
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
strTitle = "Access to Outlook Test"
objEmail.To = strTo '-an e-mail address
objEmail.Body.printtext Text:="Report for today:"
objEmail.Body.printparagraph
wdParg.Paste 'to paste my report
objEmail.Body.printparagraph
objEmail.Body.printtext Text:="If any problems call"
objEmail.Body.printparagraph
objEmail.Body = strBody
objEmail.Subject = strTitle
Set objDoc = objEmail.Attachments
objDoc.Add strAttach
' Save email in drafts folder
objEmail.Close olSave
Else
MsgBox "No Drafts Folder"
End If
End Sub