"Sendkeys" problem

PortyAL

Craigavon, N.Ireland
Local time
Today, 03:44
Joined
Apr 16, 2007
Messages
24
Hi

I use the following code to create an e-mail. (The original code is quite lengthy so I have deleted sections which are not relevant to my question).

Code:
Private Sub Command184_Click()
If IsNull(Forms![form1]![PAR Due1]) = True Then GoTo norespdate
 
Rem On Error GoTo nofiles
 
Dim strbody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim MailTo As String
Dim attnameDR As String
Dim attnameAP As String
 
attnameDR = Forms![form1]![docfolder] & "\" & Forms![form1]![Job] & " Final Report.doc"
attnameAP = Forms![form1]![docfolder] & "\Signed Action Plan.pdf"
 
'**creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
 
(SECTION OF CODE DELETED)
 
 
'***creates [URL="http://www.tek-tips.com/viewthread.cfm?qid=1479258&page=1#"]email[/URL]
 With objEmail
     .To = Forms("form1").Controls("empname").Value
     .CC = Forms("form1").Controls("contact").Value & ";Brona Slevin"
     .Subject = "Final Internal Audit Report - " & Forms![form1]!Job
     .BodyFormat = olFormatHTML
     .htmlBody = strbody
     .Importance = olImportanceHigh
     .ReadReceiptRequested = True
     .Attachments.Add attnameDR
     .Attachments.Add attnameAP
     .Display
 Rem .SaveAs Forms("form1").Controls("docfolder").Value & "\Email - Final Report.msg", olMSG
SendKeys "{pgdn}{pgdn}{enter}%is{enter}"
SendKeys "%obpcbc{enter}"
 
 
 End With
 
Set objEmail = Nothing
 
Exit Sub
 
nofiles:
MsgBox "Final Report or Action Plan is not present", vbInformation, "Cannot create e-mail"
Exit Sub
 
norespdate:
MsgBox "PAR Due not completed.", vbInformation, "Cannot create e-mail"
Exit Sub
End Sub


My query relates to the "Sendkeys" part of the code i.e.

Code:
SendKeys "{pgdn}{pgdn}{enter}%is{enter}"
SendKeys "%obpcbc{enter}"


This inserts a corporate logo as background to the e-mail and my signature at the bottom.

This works roughly every other time. When it does not work, the e-mail is created, but the background and signature are not inserted. I then close the created e-mail and run the routine again and it usually works OK the second time.

What would be the reason for this?

Thanks

AL
 
A quick stab at this would be to insert a couple DoEvents - ?
 
A quick stab at this would be to insert a couple DoEvents - ?

Many thanks!

This appears to have solved the problem!

AL
 

Users who are viewing this thread

Back
Top Bottom