Sort by Next Occurrence of Recurring Appointment for Birthdays

J

Josetta

Some things just really bug me...this was one of them.

I wanted to be able to sort Birthdays and Holidays by the next time it
occurs and Outlook just doesn't have a field for this. I'm not the
only one who's bugged by this, and since I couldn't find code anywhere
else on the web (but found lots of complaints), I thought I'd post my
solution here.

What this does is create a date field called "NextOccDate", looks to
see if the date has already passed this year and if so, adds 1 to the
year. You can drop this field from the user-defined fields into a
table-view (I used Annual Events, since that shows me all the
birthdays, etc.). This code assumes that you have categories called
"Birthday/Anniversary" and "Holiday". You may need to change it
appropriately, or take out that altogether. Since you need to manually
run this if you add new events (or as the date changes), I figure I'll
just call this whenever Outlook opens with the Auto_Open event. I
don't have tons of items, so it takes seconds. You are then able to
sort by this field and it sorts propertly, since it is defined as a
date field.

I need this because I recently took a cake decorating course and now
for "practice", I need to make a cake any time I can. Most of my
family/friends are SICK of cakes, but birthdays are a must. I need to
see who my next victim is, so I can plan accordingly. LOL

This little snippet needs to credit myriad people, groups, etc., not
the least of which is Sue Mosher, who's site www.outlookcode.com is a
must see for anyone trying to deal with Outlook programming (I'm
officially an Access programmer). With a little adjustment, you should
be able to just drop this into a module and run it.

I hope this helps.

Josetta

------

Sub SetNextOccurence()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myItem As Outlook.AppointmentItem
Dim myItems As Outlook.Items
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderCalendar)
Set myItems = myFolder.Items

For Each myItem In myItems

If myItem.Categories = "Birthday/Anniversary" Or
myItem.Categories = "Holiday" Then
If DateSerial(Year(Date), Month(myItem.Start),
Day(myItem.Start)) > Date Then
NextYear = Year(Now())
Else
NextYear = Year(Now()) + 1
End If
NextDate = DateSerial(NextYear, Month(myItem.Start),
Day(myItem.Start))

Set prop = myItem.UserProperties.Add("NextOccDate",
olDateTime)
prop.Value = NextDate
myItem.Save
End If

Next myItem

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top