UtterAccess.com
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    
 
   
graeme_706
post Aug 17 2019, 04:31 AM
Post#1



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


Hi,

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
objMail.Display
End Sub


Go to the top of the page
 
cheekybuddha
post Aug 17 2019, 05:38 AM
Post#2


UtterAccess Moderator
Posts: 11,909
Joined: 6-December 03
From: Telegraph Hill


Hi,

Try substituting the line before (Set olApp = Outlook.Application) with the following code:
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
' ...

[Untested]

hth,

d

--------------------


Regards,

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



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


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

to
CODE
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
 
graeme_706
post Aug 17 2019, 08:46 AM
Post#4



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.

Graeme

Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    12th December 2019 - 01:10 AM