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
I took your test code and modified it a bit to run in the Outlook VBA
project and to declare all the referenced object variables. In the time span
set by the filter I had 4 items in the filtered collection and was able to
add and then later retrieve the user property values.
I'm curious if you take your code and change your instantiation of
Outlook.Application to Set olOutlook = Application and run the code inside
of Outlook if you will have the same error results.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
"McKilty" <blues...@gmail.com> wrote in message
news:35ee5f98-0f92-48c2...@h40g2000pro.googlegroups.com...