Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Access Automation _ Run-time Error When Launching Microsoft Outlook 2010

Posted by: graeme_706 Aug 22 2019, 05:03 PM


I'm taking a report and generating a pdf then sending as an attachment using Microsoft Outlook 2010.

When I run this sequence, it may work 15 times, then it will fail. Error Run-time error '-2147467259 (8000-4005)' The operation failed. The messaging interfaces have returned an unknown error. If the problem persists, restart Outlook

I'm using windows 10, Access 2010 and Microsoft outlook 2010

My recovery from the error is to either force a shutdown on Microsoft Outlook (task manager / End Task) or to reboot the PC

Anyone seen this before ? Any clues how to fix ?

Here is my code :-

Private Sub Label42_Click()
Dim bcRet As Boolean
"C:\MyPDF\Invoice.pdf", False, False, 150, "", "", 0, 0, 0)
"C:\MyPDF\Breakdown.pdf", False, False, 150, "", "", 0, 0, 0)
"C:\MyPDF\Invoice.pdf", False, False, 150, "", "", 0, 0, 0)
Dim Inv4wName As String
Dim finv4Name As String
Inv4wName = Me.lstRptInv4w
finv4Name = "C:\MyPDF\Invoice_P" & Text140.Value & "_" & Text51.Value & ".pdf"
DoCmd.OpenReport Inv4wName, acViewPreview
DoCmd.OutputTo acOutputReport, Inv4wName, acFormatPDF, finv4Name
DoCmd.Close acReport, Inv4wName, acSaveNo
Dim reportName4 As String
Dim fileName4 As String
reportName4 = Me.lstRptBdown4w
fileName4 = "C:\MyPDF\Breakdown_P" & Text140.Value & "_" & Text51.Value & ".pdf"
DoCmd.OpenReport reportName4, acViewPreview
DoCmd.OutputTo acOutputReport, reportName4, acFormatPDF, fileName4
DoCmd.Close acReport, reportName4, acSaveNo
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
If olApp Is Nothing Then
MsgBox "Can't start Outlook", vbExclamation
Exit Sub
End If
End If
On Error GoTo 0
Dim objMail As Outlook.MailItem
Dim objAttach As Outlook.Attachments
Set objMail = olApp.CreateItem(olMailItem)
objMail.To = Combo7.Column(1)
objMail.Subject = "Invoice for " & Combo7.Column(3)
objMail.Body = "Hi " & Combo7.Column(2) & "," & Chr$(13) & Chr$(13) & "Please find attached Invoice " & Chr$(13) & Chr$(13) & "Thanks,"
Set objAttach = objMail.Attachments
objAttach.Add "C:\MyPDF\Breakdown_P" & Text140.Value & "_" & Text51.Value & ".pdf"
objAttach.Add "C:\MyPDF\Invoice_P" & Text140.Value & "_" & Text51.Value & ".pdf"
End Sub


Posted by: theDBguy Aug 22 2019, 05:10 PM

Hi. Unless I missed it, you don't seem to be clearing your object variables, so you may be running out of memory.

Posted by: graeme_706 Aug 22 2019, 05:33 PM


I'm self taught on Access, could I get some guidance on how I should clear the object variables ?

Kind regards,


Posted by: MadPiet Aug 22 2019, 05:53 PM

all the object variables (the ones you used Set with), like objOutlook etc

once you're done using them, you clean up:

set rs = Nothing
set objOutlook = Nothing


Otherwise, the objects remain in memory the whole time...

Posted by: graeme_706 Aug 23 2019, 12:30 PM

Thanks Madpiet, I'll give it a try

Posted by: graeme_706 Sep 18 2019, 12:50 PM

Worked a treat for me, thanks.

Posted by: theDBguy Sep 18 2019, 02:24 PM

Hi. Glad to hear you got it sorted out. Good luck with your project.