-1

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
bsg
  • 825
  • 2
  • 14
  • 34

1 Answers1

1

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
HK1
  • 11,941
  • 14
  • 64
  • 99
  • That's incredible! I can't believe that such a silly thing was the problem, but it was. I changed my forward slashes to backslashes in the path and now it runs beautifully. Thanks a lot! – bsg Apr 30 '12 at 02:39