PDA

View Full Version : [SOLVED:] Recurrence Type of yearly evaluates to daily



jboisa
04-20-2020, 08:49 AM
I am writing VBA code to gather birthdays of clients from excel, and create birthday calendar appointment items in outlook, with a recurrence pattern of yearly. The code below works, with exception of creating an appointment item with a recurrence pattern of daily, instead of yearly. Stepping through each line, I noticed that the code changes the recurrence pattern from weekly to daily, rather than yearly, as expected. I am running Excel and Outlook 2016. Here is the code:


Sub Birthday2()


Dim objOutlook As Object
Dim objnSpace As Object
Dim objFolder As Object
Dim myOccurencePattern As Object


Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")

Set myApt = objOutlook.CreateItem(1)
myApt.Subject = "Client Birthday"
myApt.Body = #1/19/2020#
myApt.Start = #1/19/2020#
myApt.AllDayEvent = True
myApt.ReminderMinutesBeforeStart = 10080

Set myOccurencePattern = myApt.GetRecurrencePattern


myOccurencePattern.RecurrenceType = olRecursYearly
myOccurencePattern.PatternStartDate = #1/19/2020#
myOccurencePattern.PatternEndDate = #1/19/2021#


myApt.Save

End Sub

Paul_Hossler
04-20-2020, 09:54 AM
Since this was primarily an Outlook question, I moved it to the Outlook forum

You'll probably get more attention in this forum

jboisa
04-20-2020, 10:11 AM
Thank You.

gmayor
04-20-2020, 09:23 PM
You can't use Outlook specific commands when processing using late binding to Outlook from Excel thus olRecursYearly is ignored. Use instead the numeric equivalent (5).


Sub Birthday2()


Dim objOutlook As Object
Dim objnSpace As Object
Dim objFolder As Object
Dim myApt As Object
Dim myOccurencePattern As Object


Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")

Set myApt = objOutlook.CreateItem(1)
myApt.Subject = "Client Birthday"
myApt.Body = #1/19/2020#
myApt.Start = #1/19/2020#
myApt.AllDayEvent = True
myApt.ReminderMinutesBeforeStart = 10080

Set myOccurencePattern = myApt.GetRecurrencePattern


myOccurencePattern.RecurrenceType = 5
myOccurencePattern.PatternStartDate = #1/19/2020#
myOccurencePattern.PatternEndDate = #1/19/2021#


myApt.Save

Set objOutlook = Nothing
Set objnSpace = Nothing
Set myOccurencePattern = Nothing
Set myApt = Nothing
End Sub

jboisa
04-22-2020, 05:36 AM
Thanks so much. I need to learn more about early and late binding. Thanks again.