McKilty
2010-08-26 17:42:04 UTC
I'm trying to write to an Outlook Calendar item user property. The
calendar is the local user's calendar and not a public calendar. The
purpose of writing to the calendar item is to later read that value
back... which seems obvious I guess. It can be an item property or a
folder property, I don't care.
When I write the value, there seems to be no problem, but when I read
the value back, Outlook says "Huh? A what now?" The error I get is
91: Object variable or With block variable not set.
I need help with this. I've been working on this project and had this
working at one point, but it's like Outlook is evolving to prevent my
code from working. lol. I'm losing my mind over here...
I pulled my code out to a simple function to test. The code is below:
Public Function WriteToCalendarTest()
'OUTLOOK
Dim olOutlook As outlook.Application
Dim nsNameSpace As NameSpace
Dim mItemCollection As Items
Dim myProp_R As ItemProperty
'OTHER
Dim sFilter As String
Set olOutlook = CreateObject("Outlook.Application")
Set nsNameSpace = olOutlook.GetNamespace("MAPI")
Set myFolder = nsNameSpace.GetDefaultFolder(olFolderCalendar)
Set myItems = myFolder.Items
myItems.Sort "[Start]", False
myItems.IncludeRecurrences = True
sFilter = "[End] >= '" & Format(Date - 7, "yyyy/mm/dd") & "' AND
[Start] <= '" & Format(Date + 10 & " 11:59 PM", "yyyy/mm/dd hh:nn") &
"'"
Set mItemCollection = myItems.Restrict(sFilter)
'LOOP CALENDAR ITEMS AND SET VALUE
For Each Item In mItemCollection
Set myProp_R = Item.UserProperties.Add("RAPPID", olText)
myProp_R.Value = "test text"
Item.Save
Next
Set mItemCollection = myItems.Restrict(sFilter)
For Each Item In mItemCollection
Set myProp_R = Item.UserProperties.Find("RAPPID")
MsgBox myProp_R.Value 'RETURNS ERROR 91 - Object variable or With
block variable not set
Next
Set mItemCollection = Nothing
Set myItems = Nothing
Set myFolder = Nothing
Set nsNameSpace = Nothing
Set olOutlook = Nothing
Set Utils = CreateObject("Redemption.MAPIUtils")
Utils.Cleanup
End Function
calendar is the local user's calendar and not a public calendar. The
purpose of writing to the calendar item is to later read that value
back... which seems obvious I guess. It can be an item property or a
folder property, I don't care.
When I write the value, there seems to be no problem, but when I read
the value back, Outlook says "Huh? A what now?" The error I get is
91: Object variable or With block variable not set.
I need help with this. I've been working on this project and had this
working at one point, but it's like Outlook is evolving to prevent my
code from working. lol. I'm losing my mind over here...
I pulled my code out to a simple function to test. The code is below:
Public Function WriteToCalendarTest()
'OUTLOOK
Dim olOutlook As outlook.Application
Dim nsNameSpace As NameSpace
Dim mItemCollection As Items
Dim myProp_R As ItemProperty
'OTHER
Dim sFilter As String
Set olOutlook = CreateObject("Outlook.Application")
Set nsNameSpace = olOutlook.GetNamespace("MAPI")
Set myFolder = nsNameSpace.GetDefaultFolder(olFolderCalendar)
Set myItems = myFolder.Items
myItems.Sort "[Start]", False
myItems.IncludeRecurrences = True
sFilter = "[End] >= '" & Format(Date - 7, "yyyy/mm/dd") & "' AND
[Start] <= '" & Format(Date + 10 & " 11:59 PM", "yyyy/mm/dd hh:nn") &
"'"
Set mItemCollection = myItems.Restrict(sFilter)
'LOOP CALENDAR ITEMS AND SET VALUE
For Each Item In mItemCollection
Set myProp_R = Item.UserProperties.Add("RAPPID", olText)
myProp_R.Value = "test text"
Item.Save
Next
Set mItemCollection = myItems.Restrict(sFilter)
For Each Item In mItemCollection
Set myProp_R = Item.UserProperties.Find("RAPPID")
MsgBox myProp_R.Value 'RETURNS ERROR 91 - Object variable or With
block variable not set
Next
Set mItemCollection = Nothing
Set myItems = Nothing
Set myFolder = Nothing
Set nsNameSpace = Nothing
Set olOutlook = Nothing
Set Utils = CreateObject("Redemption.MAPIUtils")
Utils.Cleanup
End Function