X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Runtime Error 462, Access 2010    
post Aug 17 2019, 04:31 AM

Posts: 77
Joined: 3-August 10
From: Scotland, UK


I've got some VBA code working on a Windows 7 PC with Access 2003, and never had issues in years.

Putting it on to a Windows 10 machine and using Access 2010, the VBA works every second attempt. What the code does is generates a pdf from an access report and sends it as an attachment to Microsoft Outlook 2010.

The error is runtime error 462, and the highlighted code when the error happens is "Set objMail = olAPP.CreateItem(olMailItem" as highlighted in bold.

Please go easy on me as i find all this quite difficult, any pointers greatly appreciated.

I found on Microsoft web search the following, but do not understand it: To resolve this problem, modify the code so each call to an Excel object, method, or property is qualified with the appropriate object variable.

Here's the code:-

Private Sub Command0_Click()
Dim blRet As Boolean
blRet = ConvertReportToPDF(Me.lstRptANY, vbNullString, _
"C:\MyPDF\Carer_List.pdf", False, False, 150, "", "", 0, 0, 0)
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim objAttach As Outlook.Attachments
Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)
objMail.To = Text23
objMail.CC = "contact@********.co.UK"
objMail.Subject = "Carer List Attached for " & Text5 & " " & Text7 & " for WW" & Combo12.Value
objMail.Body = "Hi " & Text21 & ", " & Chr$(13) & Chr$(13) & "Please find attached carer list for " & Text5 & " " & Text7 & " for WW" & Combo12.Value & Chr$(13) & Chr$(13) & "Thanks," & Chr$(13) & Chr$(13) & Text3.Value
Set objAttach = objMail.Attachments
objAttach.Add "c:\MyPDF\Carer_List.pdf"
'change this file name too
End Sub

Go to the top of the page
post Aug 17 2019, 05:38 AM

UtterAccess VIP
Posts: 11,524
Joined: 6-December 03
From: Telegraph Hill


Try substituting the line before (Set olApp = Outlook.Application) with the following code:
' Set olApp = Outlook.Application
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If err Then
  err = 0
  Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
' ...






David Marten
Go to the top of the page
post Aug 17 2019, 07:30 AM

Posts: 2,678
Joined: 4-February 07
From: USA, Florida, Delray Beach

In order to create a New Instance of the Outlook Application, change
Set olApp = Outlook.Application

Set olApp = New Outlook.Application

This post has been edited by ADezii: Aug 17 2019, 07:31 AM
Go to the top of the page
post Aug 17 2019, 08:46 AM

Posts: 77
Joined: 3-August 10
From: Scotland, UK

Hi Cheeky Buddha,

Thank you very much, this worked for me, thanks so much for your quick reply.


Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    17th October 2019 - 10:27 AM