Edit: Moved to General in hopes of an answer as no one in Target: Windows wast biting
Thanks to John Hansen’s example https://forum.xojo.com/5315-addressbook-object-for-windows-outlook-import-expo/0 I have almost refactored my Outlook Calendar code to be much more efficient. I have one niggling problem left.
[code] Dim oResults() As VAD_CalendarEvent
Dim olFolderCalendar As Integer = 9
Dim oApp As OLEObject
oApp = New OLEObject("Outlook.Application")
Dim oNameSpace As OLEObject
oNameSpace = oApp.GetNameSpace("MAPI")
Dim oRecipient As OLEObject
oRecipient = oNameSpace.CreateRecipient(uName)
Dim oCalendar As OLEObject
oCalendar = oNameSpace.GetSharedDefaultFolder(oRecipient,olFolderCalendar)
Dim oItems As OLEObject
Dim oItemsInDateRange As OLEObject
Dim oAppt As OLEObject
Dim strRestriction As String
Dim oEvent As VAD_CalendarEvent
strRestriction = "[Start] >= '" + _
dtStart.ShortDate + " " + dtStart.ShortTime _
+ "' AND [End] <= '" + _
dtEnd.ShortDate + " " + dtEnd.ShortTime + "'"
oItems = oCalendar.Items
oItems.IncludeRecurrences = True
oItems.Sort "[Start]"
''Restrict the Items collection for the date range
oItemsInDateRange = oItems.Restrict(strRestriction)
oItemsInDateRange.Sort "[Start]"
'Dim count As int64 = oItemsInDateRange.Count ' Neither this or below work
Dim count As int64 = oItemsInDateRange.Value("Count")
For i As Integer = 1 to count
try
oAppt = oItemsInDateRange.Item(i)
oEvent = New VAD_CalendarEvent
oEvent.sEventName = oAppt.Subject
oEvent.dtmStart.TotalSeconds = oAppt.Start
oEvent.dtmEnd.TotalSeconds = oAppt.Start + (oAppt.Duration * 60)
oEvent.sLocation =oAppt.Location
oEvent.sDescription = oAppt.Body
oResults.Append oEvent
catch OLEerr as OLEException
'MsgBox OLEerr.Message
exit
end try
Next
Return oResults[/code]
The problem is the “count” variable. No matter how I try and extract it I get 2147483647 as a value. The actual value is much lower. I can get the appointment information I need but I need to catch an OLEexception to exit the loop.
The exception iis Unknown error:1, (failed on “Item”) - I would expect an out of bounds.
The count property is correct if I do not use " oItems.IncludeRecurrences = True" but I do need the recurring appointments.
Any OLE gurus that can point me to the proper syntax?
Thanks.