Call an Outlook Macro From Access

A

Antonio Macias

Hello all

My question is how can I call an Outlook Macro from Access
via Visual Basic?
How do I Link those programs to create an automatitation?

I want to do this because my Outlook Macro is to send and
receive mails:

Sub SendandReceive()

Dim oCtl As Office.CommandBarControl
Dim oPop As Office.CommandBarPopup
Dim oCB As Office.CommandBar

'use the Send/Receive on All Accounts action in the Tools
'menu to send the item from the Outbox, and receive new
items
Set oCB = Application.ActiveExplorer.CommandBars("Menu
Bar")
Set oPop = oCB.Controls("Herramientas")
Set oPop = oPop.Controls("Enviar y recibir")
Set oCtl = oPop.Controls("Enviar y recibir Todo")
oCtl.Execute

Set oCtl = Nothing
Set oPop = Nothing
Set oCB = Nothing

End Sub

I would like to call this macro pressing a button from my
Access Data base

Thanks in advance
Antonio Macias
Mexico City
 
S

Sue Mosher [MVP-Outlook]

If the procedure is declared Public in ThisOutlookSession, you should be
able to call it as a method of the Outlook Application object. Note,
however, that this technique is unsupported.

If that doesn't work, then recreate the macro in Access VBA.
 
A

Antonio Macias

Dear Sue,

I have moved my code to ThisOutlookSession, but when I
try to run IT from Access I got error "438".
This is the code I have in Access

Private Sub Comando0_Click()

Dim objOL As Outlook.Application

Set objOL = CreateObject("Outlook.Application")
Call objOL.SendandReceive

Set objOL = Nothing

End Sub

Could you please let me know what is wrong?

Thanks in advance

Antonio Macias
Mexico City
-----Original Message-----
If the procedure is declared Public in
ThisOutlookSession, you should be
 
S

Sue Mosher [MVP-Outlook]

Did you try stepping through the code? What does the SendandReceive
procedure do?

It's quite possible that this method is not available to you in Access. It
definitely works from Outlook form code, but that's still within the Outlook
environment. You may need to just copy the code to your Access VBA project.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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