Open Calendar via MS Access 2003 form

S

StuJol

Does anyone know any code i can use please to open the outlook
calendar via a command button on a microsoft access from?
 
K

Ken Slovak - [MVP - Outlook]

Do you mean to open Outlook and display the default Calendar folder?

Sub ShowCalendar()
Dim oOL As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oExplorer As Outlook.Explorer
Dim oFolder As Outlook.MAPIFolder

Set oOL = CreateObject("Outlook.Application")

Set oNS = oOL.GetNameSpace("MAPI")
oNS.Logon

Set oFolder = oNS.GetDefaultFolder(olFolderCalendar)
If oNS.Explorers.Count = 0 Then
Set oExplorer = oNS.Explorers.Add(oFolder)
Else
Set oExplorer = oOL.ActiveExplorer
Set oExplorer.CurrentFolder = oFolder
End If

oFolder.Display

End Sub

There's no error trapping there and you need to set all objects = Nothing at
the end of the Sub but that should give you the idea.
 
S

StuJol

When i run your code from my cmd button i get this error msg "RunTime Error
438, Object doesnt support this property or method" and code breaks at If
oNS.Explorers.Count = 0 Then
 
K

Ken Slovak - [MVP - Outlook]

That'll teach me to write code on the fly. Sorry about that.

Use oOL.Explorers.Count and oOL.Explorers.Add.

The Explorers collection is exposed by the Application object, not the
NameSpace object.
 
S

StuJol

Many Many thanks, you've solved something i've been trying to do for ages.
Once gain thanks.

One other thing, if you dont mind. The calendar opens as a small window in
the middel of my screen, do you know how to open it maximised?? i tried
DoCmd.Maximize at the end of the code but it maximises my form, not the
calendar

All the best for the new year
 
K

Ken Slovak - [MVP - Outlook]

Explorer.WindowState = olMaximized. You also haved enum members in the
OlWindowState enum for olMinimized and olNormalWindow.
 
Top