Hello,
I am now truly in despair. I am currently trying to create a series appointment in Outlook using another MS app. The appointment is to be entered in the student calendar, which works as far as it goes. However, the date is not correct.
I use 03/10/2001 as a test date, but a repetition for 12 October is generated. Always for the current day instead of the test date one. The month is correct
This is my test code:
Code:
Sub TEST_SerialAppointment()
'---------------------------------------------------------------------
' Purpose: Creating a serial appointment in a specific calendar
'---------------------------------------------------------------------
Dim oOutlook As Outlook.application
Dim oNameSpace As Outlook.NameSpace
Dim oCalendar As Outlook.Folder
Dim oMyCalendar As Outlook.Folder
Dim oAppointment As Outlook.AppointmentItem
Dim datStart As Date
Const datBirthday As Date = "03/10/2001"
'the pattern shall start from today
datStart = DateSerial(Year(Date), Month(datBirthday), Day(datBirthday))
' create Outlook-Application-Objekt
Set oOutlook = CreateObject("Outlook.Application")
' Namespace
Set oNameSpace = oOutlook.GetNamespace("MAPI")
'Standard Calendar
Set oCalendar = oNameSpace.GetDefaultFolder(olFolderCalendar)
'My Calendar where the entry shall be made
Set oMyCalendar = oNameSpace.GetDefaultFolder(olFolderCalendar).Folders("student (Nur dieser Computer)")
'Entry
Set oAppointment = oMyCalendar.Items.Add
With oAppointment
.GetRecurrencePattern.RecurrenceType = olRecursYearly
.GetRecurrencePattern.Occurrences = 5
.GetRecurrencePattern.Duration = 24 * 60
.GetRecurrencePattern.PatternStartDate = datStart
.GetRecurrencePattern.StartTime = 0
.GetRecurrencePattern.EndTime = 0
.Subject = "Test_entry"
.Body = "test"
.BusyStatus = olFree
.Categories = "Test"
.Location = "location"
.AllDayEvent = True
.ReminderMinutesBeforeStart = 24 * 60
.Duration = 24 * 60
.Save
.Display
End With
On Error Resume Next
Set oOutlook = Nothing
Set oNameSpace = Nothing
Set oCalendar = Nothing
Set oMyCalendar = Nothing
Set oAppointment = Nothing
End Sub
I'm programming some years now with MS Access but no experiences so far with Outlook. My problem is that I do not understand why the appointment is setup wrongly (Right month and year but always using the current day instead of the one I use in the code).
When I setup this appointment manually in Outlook and read the settings out in VBA the values are the same as in the code. That confuses me a lot.
Hopefully someone has a good hint for me.
Kind regards