Link to home
Start Free TrialLog in
Avatar of AHEC
AHEC

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Michael Vasilevsky
Michael Vasilevsky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AHEC
AHEC

ASKER

Adding the missing line fixed it. Thanks!