Running an MS Access Query from Outlook using VBA

M

Michael Ryle

Hi All,

I'm using the following Outlook macro code to run a query in MS Access whenever a calendar item (appointment) is added in Outlook:

Public WithEvents myOlItems As Outlook.Items

Private Sub Application_Startup()
Set myOlItems = _
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)

Dim appAccess As Access.Application

...

Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "... my database path ..."
appAccess.DoCmd.RunSQL ("... my query ...")
appAccess.CloseCurrentDatabase
appAccess.Quit

End Sub

The problem I have is that when this code runs it causes the MS Access window to flash on and off, which is confusing and annoying to the user.

Is there are way of running an MS Access query from Outlook "in background", i.e., without causing the MS Access window to flash? Thanks.
 
K

Ken Slovak - [MVP - Outlook]

Set appAccess = CreateObject("Access.Application")
appAccess.Visible = False




Michael Ryle said:
Hi All,

I'm using the following Outlook macro code to run a query in MS Access
whenever a calendar item (appointment) is added in Outlook:
Public WithEvents myOlItems As Outlook.Items

Private Sub Application_Startup()
Set myOlItems = _
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)

Dim appAccess As Access.Application

...

Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "... my database path ..."
appAccess.DoCmd.RunSQL ("... my query ...")
appAccess.CloseCurrentDatabase
appAccess.Quit

End Sub

The problem I have is that when this code runs it causes the MS Access
window to flash on and off, which is confusing and annoying to the user.
Is there are way of running an MS Access query from Outlook "in
background", i.e., without causing the MS Access window to flash? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top