Hi all, we use Office 2010 I'm trying to create an appointment from an Access database every time a holiday entry gets created. I have coded this using info I've found on the net but can't seem to get it quite right to add to our shared calendar which resides in Public Folders\All Public Folders\Central Calendar. This is a snippet of code I have:
Set olPublicFolder = olNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders)
this gives a permission error but I assume it is because it returns the root of Public folders and it needs to be the subfolder (Central Calendar)? I've tried this:
Set olPublicFolder = olNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders) & "\All Public Folders\Central Calendar"
but it errors with object required. I found some code for returning the entryid of the calendar and tested this, it does display the correct calendar so it is not a permissions problem. If I substitute the entryid string instead of the path to the calendar I get the same object required error. Can anyone please help me with the correct code for writing to a calendar in a public folder? Thanks...
Full code below:
Sub CreateCalEntry(StartHol As Date, EndHol As Date, _
Subject As String, CalRef As String, Body As String, _
Optional AddToShared As Boolean = True)
'Lead date = expect notify from data
'Due date - expect event due date
'Add to shared - add item to central calendar
Const olApItem = 1
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olPublicFolder As Outlook.MAPIFolder
Dim olItem As Outlook.AppointmentItem
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olPublicFolder = olNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders) & "\All Public Folders\Central Calendar"
'Set olPublicFolder = olApp.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Parent & "\All Public Folders\Central Calendar"
Set oItem = olPublicFolder.Items.Add(olApItem)
With olItem
.Subject = Subject & " Holiday"
'.Location = Location
'.Body = Body
.Mileage = CalRef
.Start = StartHol
.End = EndHol
'If AddToShared = True Then
.Move objFolder
'End If
End With
Set oItem = Nothing
Set olApp = Nothing
Set olPublicFolder = Nothing
Set olNameSpace = Nothing
Set olPublicFolder = olNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders)
this gives a permission error but I assume it is because it returns the root of Public folders and it needs to be the subfolder (Central Calendar)? I've tried this:
Set olPublicFolder = olNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders) & "\All Public Folders\Central Calendar"
but it errors with object required. I found some code for returning the entryid of the calendar and tested this, it does display the correct calendar so it is not a permissions problem. If I substitute the entryid string instead of the path to the calendar I get the same object required error. Can anyone please help me with the correct code for writing to a calendar in a public folder? Thanks...
Full code below:
Sub CreateCalEntry(StartHol As Date, EndHol As Date, _
Subject As String, CalRef As String, Body As String, _
Optional AddToShared As Boolean = True)
'Lead date = expect notify from data
'Due date - expect event due date
'Add to shared - add item to central calendar
Const olApItem = 1
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olPublicFolder As Outlook.MAPIFolder
Dim olItem As Outlook.AppointmentItem
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olPublicFolder = olNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders) & "\All Public Folders\Central Calendar"
'Set olPublicFolder = olApp.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Parent & "\All Public Folders\Central Calendar"
Set oItem = olPublicFolder.Items.Add(olApItem)
With olItem
.Subject = Subject & " Holiday"
'.Location = Location
'.Body = Body
.Mileage = CalRef
.Start = StartHol
.End = EndHol
'If AddToShared = True Then
.Move objFolder
'End If
End With
Set oItem = Nothing
Set olApp = Nothing
Set olPublicFolder = Nothing
Set olNameSpace = Nothing