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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remote procedure call failed(PLEASE HELP)

Status
Not open for further replies.

mygmat123

Technical User
Jun 28, 2004
56
0
0
US
I get an error when I try to run this send an email with the following code.

PLEASE HELP. This was working perfectly them all of a sudden it stopped and I get this error. What is causing this error?


MESSAGE:
runtime error: -2147023170 '(800706be)'
Automation error The remote procedure call failed




Function Send_Outlook(Optional strTO As String = "myemail@domain.com", Optional strCC As String, Optional strBCC As String, Optional Subject As String = "Report (bla bla)", Optional Body As String = "Attached please find reports", Optional ByRef path1 As Variant)


'*********************************************************
' TURN ON CLICK_ YES
Dim wnd As Long
Dim uClickYes As Long
Dim Res As Long

'Register a message to send
uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")

' Find ClickYes Window by classname
wnd = FindWindow("EXCLICKYES_WND", 0&)

' Send the message to Resume ClickYes
Res = SendMessage(wnd, uClickYes, 1, 0)

' ...
' Do some Actions


'**************************************
Dim dbName


Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem


Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

If strTO = "" Then
strTO = "myemail@domain.com"
End If



With MailOutLook

.TO = strTO
.CC = strCC
.BCC = strBCC

.Subject = Subject
.Body = Body

End With


'*****************************************************************
Dim objattach As Variant

If Testarray(path1) Then

For Each objattach In path1
If Not IsEmpty(objattach) And Not IsNull(objattach) Then
objattach = Right(objattach, Len(objattach) - 1)

'needs to check is file exists******************
MailOutLook.attachments.Add objattach
End If
Next
End If


MailOutLook.Send

'Record message as sent in tbl_email_log

Call email_log(strTO, strCC, strBCC, Subject, Body, "Outlook", path1)


'Timer function********************************************
Dim PauseTime, Start, Finish, TotalTime

PauseTime = 5 ' Set duration.
Start = timer ' Set start time.
Do While timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time


'*********************************************************

'appOutLook.Quit
Set MailOutLook = Nothing
Set appOutLook = Nothing


' ...
' Send the message to Suspend ClickYes
Res = SendMessage(wnd, uClickYes, 0, 0)

End Function


 
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem


Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)


I think the mailoutlook object is not getting set for some reason, but I don't know why

PLEASE HELP I REALLY NEED THIS TO WORK!!!
THANK YOU
 
Hallo,

What line does the error occur on?

- Frink
 
the error occurs happens at "mailoutlook.send".
 
But if I click on any of the objects like .to, .cc, .bcc,.subject,.body etc.

then I see that the .body=<variable or with block variable not set>


With MailOutLook

.TO = strTO
.CC = strCC
.BCC = strBCC

.Subject = Subject
.Body = Body

End With




 
Hallo,

Do you have Outlook running?

I think it has to be running for this to work.
Try it, if it fails,
Shell "outlook"
and retry. Set a flag if you open it so you can close it afterwards,

- Frink
 
yes, it worked after a opened outlook, but in the past my outlook was closed and it sent just fine.

Why would that be? Maybe, when I quit outlook in the past it did not fully clear from the memory?

What code should I use to open outlook and close outlook? Since this seems to be needed now.

Thank you for your help!!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top