I'm trying to run a subroutine in MS Access when an email is received in Outlook.
I'm using an Access.Application object and its Run method.
I get the following error: Method Run of Object _Application failed.
Private Sub Application_newmail()
MsgBox "New mail"
Dim accessdb As Access.Application
Set accessdb = CreateObject("Access.Application")
accessdb.opencurrentdatabase "C:/Camps.accdb", False
accessdb.Run "test"
accessdb.CloseCurrentDatabase
Set accessdb = Nothing
End Sub
The "test" subroutine is an empty sub (after I tried and failed to call an actual sub) in the Checkdb module.
I am running Office 2007.
I tested your code using VBScript instead of Outlook. Your code worked fine for me, except I did change your forward slash to a backslash in your database path: "C:\Camps.accdb"
Make sure you have your "Test" function/sub marked as Public.
Public Function Test()
MsgBox "Test Works"
End Function