The code below is a sample to get you started. It retreives all items with a
specific value in a custom property and deletes it. I've added comments where
you'll start your own snooping...
Private Function deleteOutlookAppointmentByTransportId(lngTransportID As Long)
'Use generic objects to avoid having to set a reference
Dim objOutlook As Object
Dim nms As Object
'Dim objOutlook As Outlook.Application
'Dim nms As Outlook.NameSpace
'Dim targetCalendar As Outlook.MAPIFolder
'Dim targetItems As Outlook.Items
'Dim targetAppointment As Outlook.AppointmentItem
Dim targetCalendar As Object
Dim targetItems As Object
Dim i As Integer
Dim aOutlookEntryIds()
Dim targetAppointment As Object
Dim strFilter As String
Dim intTargetItemCount As Integer
'Create the Outlook objects that we'll be working with here
Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
'Select the folder that we're snooping around in
Set targetCalendar = nms.GetDefaultFolder(WMS_olFolderCalendar)
'Get the items that we're working with based on a specific criteria
strFilter = "[dbAccessId]=" & Chr(34) & lngTransportID & Chr(34)
Set targetItems = targetCalendar.Items.Restrict(strFilter)
ReDim aOutlookEntryIds(targetItems.Count)
For i = 1 To targetItems.Count
Debug.Print i
aOutlookEntryIds(i) = targetItems(i).EntryID
Next i
intTargetItemCount = targetItems.Count
'Loop through the items and print their properties (I accidently deleted
a For i ... Next loop here but its easy to add it back in
Set targetAppointment = nms.GetItemFromID(aOutlookEntryIds(i))
Debug.Print targetAppointment.UserProperties(1),
targetAppointment.Start, targetAppointment.Subject
targetAppointment.Delete
Debug.Print "Appoint ID: " & aOutlookEntryIds(i) & " Deleted"
Set targetItems = Nothing
Set targetCalendar = Nothing
Set nms = Nothing
Set objOutlook = Nothing
End Function
Ken Warthen said:
I'm having difficulty creating a function to retrieve the properties, such as
To, From, Subject, Date, from Outlook MailItems (.msg files) that are stored
on a server outside of Outlook. I have a form in an Access 2007 application
where the properties will be accessed by users. I wasn't sure if I should
post here or in the MS Access forum, but thought there would be more Outlook
expertise here. Any help or direction would be greatly appreciated.
Ken