Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invoke Outlook menu item from code

Status
Not open for further replies.

Eupher

MIS
Jul 18, 2002
1,724
US
I'm working on an Access 2K3 database that writes calendar appointments to an e-mail/groupware app called Mirapoint. But I can't write directly to the Mirapoint server (long story, but bottom line, it's a web-based appliance with no API) - so I have to write the appointments to Outlook, then synchronize the calendar with an Outlook add-in called SynQ. The SynQ add-in appears in the Outlook client under the "Tools" menu on the main menu bar. My first idea was to create an instance of Outlook and invoke the SynQ command after the appointment is written, so it gets to the server immediately with no user intervention. Here's the code I'm using:
Code:
Dim objOutlook As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim myNameSpace As Outlook.NameSpace
Dim myInspector As Outlook.Inspector
Set objOutlook = CreateObject("Outlook.Application")
Set myNameSpace = objOutlook.GetNamespace("MAPI")
myNameSpace.Logon "xyxyxyxyx", "zyzyzyzyz", False, True
Set objAppt = objOutlook.CreateItem(olAppointmentItem)
Set myInspector = objAppt.GetInspector
With objAppt
    .Start = Me!ApptStartDate & " " & Me!ApptTime
    .Duration = Me!ApptLength
    .Subject = Me!Appt
    If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
    If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation
    If Me!ApptReminder Then
        .ReminderMinutesBeforeStart = Me!ReminderMinutes
        .ReminderSet = True
    End If
    .Recipients.Add ("xxxxx@yyyy.zzz")
    .Recipients.Add ("yyyyy@zzzz.xxx")
    .Save
    Me!ApptID = .EntryID
    .Close (olSave)
End With
[highlight]myInspector.CommandBars("Menu Bar").Controls("Tools").Controls("Synchronize with SynQ").accDoDefaultAction[/highlight]
The code breaks on the highlighted line with "Error 5: Invalid procedure call or argument".

Does anyone know how to do this? Thanks!

Ken S.
 
Have a look at the FindControl and Execute methods in the Outlook's VBE Object browser.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi, PHV,

I couldn't find the FindControl method in the object browser, but Execute worked, once I set default folder and explorer variables and referred to the menu item using THE CORRECT NAME! Doh!

Here's the code that works:
Code:
Dim objOutlook As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myExplorer As Outlook.Explorer
Set objOutlook = CreateObject("Outlook.Application")
Set myNameSpace = objOutlook.GetNamespace("MAPI")
myNameSpace.Logon "XXXXXXXX", "yyyyyyyy", False, True
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myExplorer = myFolder.GetExplorer
Set objAppt = objOutlook.CreateItem(olAppointmentItem)
With objAppt
    .Start = Me!ApptStartDate & " " & Me!ApptTime
    .Duration = Me!ApptLength
    .Subject = Me!Appt
    If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
    If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation
    If Me!ApptReminder Then
        .ReminderMinutesBeforeStart = Me!ReminderMinutes
        .ReminderSet = True
    End If
    .Recipients.Add ("abcde@1234.xyz")
    .Recipients.Add ("edcba@1234.xyz")
    .Save
    Me!ApptID = .EntryID
    .Close (olSave)
End With
[highlight]myExplorer.CommandBars("Menu Bar").Controls("Tools").Controls("Synchronize [b][red]using[/red][/b] SynQ").Execute[/highlight]
Thanks again!

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top