Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendObject questions

Status
Not open for further replies.

f100engineer

Technical User
Nov 21, 2002
6
US
Hi, 1st post here.
I am trying to automate a morning story report for my company. Before I took this position, someone had made code to do it, but it isn't totally automated and the code is long. I think it could be simplified.
Here's the old code:
Private Sub Output_Composite_Sto_Click()
On Error GoTo Output_Composit_Sto_Click_Error

Dim sFileName As String
Dim TaskID As Variant

sReportName = "Composite Morning Story"
sFileName = "C:\f100CMornstor.doc"
DoCmd.OutputTo acOutputReport, sReportName, acFormatRTF, sFileName, True
glrDelay (2000)
SendKeys "^a^c", True
TaskID = Shell("C:\Program Files\Exchange\Exchng32.exe", vbMaximizedFocus)
'start new message
glrDelay (2000)
SendKeys "%mn", True
glrDelay (1000) ' 1 second delay
'Default location is the "to" field, tabs move to the next field
SendKeys "F100 composite Dept 742{TAB}{TAB}F100 Composite Morning Story{TAB}^v"
'next step is "^V" which has problems
'so manual pass this point


Output_Composit_Sto_Click_Exit:
Exit Sub

Output_Composit_Sto_Click_Error:
Select Case Err.Number
Case Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, , "Composite Morning Story"
Resume Output_Composit_Sto_Click_Exit
End Select
End Sub




Here is the newer code I am trying:

DoCmd.SendObject acSendReport, "Composite Morning Story", acFormatRTF, morning story,,"F100 Composite Morning Story",,False

It opens up an email with the TO filled out correct, the SUBJECT filled out correct, and attached Word doc in the body. But it doesn't automatically send the email. I thought that is what the last part "false" was for.

Also, at attaches the report to the email as an attachment. I would rather it paste its text into the email. Is there a way to do this?

ONE more question. I would like to be able to add the current date to the end of the subject line, but haven't had any luck finding a way to do this.

TIA,
-S.Huskins
 
I'm not sure about the first question; but for the second, try adding the following line to the subject part of the command ...
& Date()
 
For your first question: set your mail client to send messages immediately.
Second question: you can't use SendObject for this purpose.
If you use Outlook, you can do it as follows:

1. Paste the code below in a module
2. Output the report in html format to a file on disk (I used C:\FileName.html to test it)
3. Call the sub and it will send the report as html body.

However, keep in mind that multiple page reports are saved in multiple html files. You will have to take care of that too.

Sub SendHtmlBody()
Dim strline
Dim myOlApp, myNameSpace, myMailItem
Dim msgHtmlBody
Open "C:\FileName.html" For Input As #1
Do Until EOF(1)
Line Input #1, strline
msgHtmlBody = msgHtmlBody & strline
Loop
Close #1
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myMailItem = myOlApp.CreateItem(olMailItem)
With myMailItem
.To = "recipient@isp.net"
.Subject = "Test Html body " & Date
.HTMLBody = msgHtmlBody
.Send
End With
Set myMailItem = Nothing
Set myNameSpace = Nothing
Set myOlApp = Nothing
End Sub

Third question: dpimental is right.
Good luck
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
THANKS EVERYONE! I got it to work prefectly. I didn't have to do the HTML thing because I changed the OutputTo format to RTF, changed the file extension to .DOC, then changed the WITH > .HTMLBody to just .Body

It simply pastes the document with rich text features in the email body.

Here is the code:


Private Sub Output_Composite_Sto_Click()
On Error GoTo Output_Composit_Sto_Click_Error
Dim strline
Dim myOlApp, myNameSpace, myMailItem
Dim msgHtmlBody As String

DoCmd.OutputTo acOutputReport, "Composite Morning Story", acFormatRTF, "C:\morningstory.doc", False
Open "C:\morningstory.doc" For Input As #1
Do Until EOF(1)
Line Input #1, strline
msgHtmlBody = msgHtmlBody & strline
Loop
Close #1
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myMailItem = myOlApp.CreateItem(olMailItem)
With myMailItem
.To = "email@isp.com"
.Subject = "F100 Composite Morning Story " & DATE
.Body = msgHtmlBody
.Send
End With
Set myMailItem = Nothing
Set myNameSpace = Nothing
Set myOlApp = Nothing

Output_Composit_Sto_Click_Exit:
Exit Sub

Output_Composit_Sto_Click_Error:
Select Case Err.Number
Case Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, , "Composite Morning Story"
Resume Output_Composit_Sto_Click_Exit
End Select
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top