Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1292
  • Last Modified:

Call MSACCESS function from Outlook

I have code to call an Access function from Outlook when a new mail item is added to a specific folder. The Access database is always open when Outlook is open.

In ThisOutlookSession I have

Public WithEvents myOlItems As Outlook.Items

Public Sub Application_Startup()
    Set myOlItems = Application.GetNamespace("Mapi").Folders("Mailbox - Media Center").Folders("Inbox").Folders("Accepted Calls").Items
End Sub

Public Sub myOlItems_ItemAdd(ByVal Item As Object)

Dim acApp As Access.Application
   Set acApp = GetObject(, "Access.Application")
   acApp.Application.Run ("Out_Check")
End Sub

Open in new window


In Access I have

Public Sub Out_Check()
    Call Forms("Enter Calls").Check_Mail_Click
End Sub

Open in new window


When I first test the code it runs fine, but if I go back later and try it I get a  7952 "You have made an illegal function call" in Outlook  at
 
  acApp.Application.Run ("Out_Check")

Open in new window


I can't figure out why it runs OK if I redo it, but then starts giving the error again after a while.
0
AHEC
Asked:
AHEC
1 Solution
 
Michael VasilevskySolutions ArchitectCommented:
Have you tried clearing the acApp variable after each time? I.e.

Public Sub myOlItems_ItemAdd(ByVal Item As Object)

   Dim acApp As Access.Application
   Set acApp = GetObject(, "Access.Application")
   acApp.Application.Run ("Out_Check")
   Set acApp = Nothing
End Sub
0
 
AHECAuthor Commented:
Adding the missing line fixed it. Thanks!
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now