Retrieving Appointment with known user define field

I have a code to programmatically create an outlook appointment with user defined property. See below

With objOutlookAppointment

    .Start = datStart
    .Subject = strSubject
    
    If datEnd <> #12:00:00 AM# Then .End = datEnd
    If Not IsMissing(strDuration) Then .Duration = strDuration
    If Not IsMissing(strmsg) Then .Body = strmsg
 
    .Save
    
 If booStoreApptID = True Then
    
           .ItemProperties.Add "GAID", olText, True
          .ItemProperties.item("GAID").Value = .globalAppointmentID
          .Save

    End If

End With

Open in new window


However, I have not been able to get a code to retrieve the appointment based on the user defined value. Can anyone help with a code for that.
LVL 16
SheilsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omgangIT ManagerCommented:
Give this a shot.
There are three commented lines I used to add the user property and a value to the Outlook calendar item.  The procedure outputs to the Immediate window the following:
...
...
DownloadState
InternetCodepage
MarkForDownload
IsConflict
MeetingWorkspaceURL
AutoResolvedWinner
Conflicts
PropertyAccessor
SendUsingAccount
GlobalAppointmentID
ForceUpdateToAllAttendees
StartUTC
EndUTC
StartInStartTimeZone
EndInEndTimeZone
StartTimeZone
EndTimeZone
ConversationID
RTFBody
GAID
 ----- Value = Testing


You can see that it successfully finds your user defined property and its value.
OM Gang

Public Function FindOutlookAppointmentItem() As Boolean

On Error GoTo Err_FindOutlookAppointmentItem

    Dim olOutlook As New Outlook.Application
    Dim olNS As Outlook.Namespace
    Dim olCalendar As Outlook.MAPIFolder
    Dim olCalItem As Outlook.AppointmentItem
    Dim olProp As Object
    
    Set olNS = olOutlook.GetNamespace("MAPI")
    
    Set olCalendar = olNS.GetDefaultFolder(olFolderCalendar)
    
    Debug.Print olCalendar.Items.Count
    
    For Each olCalItem In olCalendar.Items
        If olCalItem.Subject = "My Subject Line" Then
            'olCalItem.ItemProperties.Add "GAID", olText, True
            'olCalItem.ItemProperties.Item("GAID").Value = "Testing"
            'olCalItem.Save
            
            For Each olProp In olCalItem.ItemProperties
                Debug.Print olProp.Name
                If olProp.Name = "GAID" Then
                    Debug.Print " ----- Value = " & olProp.Value
                End If
            Next olProp
        End If
        'Exit For
    Next

Exit_FindOutlookAppointmentItem:
        'destroy object variables
    Set olCalendar = Nothing
    Set olNS = Nothing
   Exit Function

Err_FindOutlookAppointmentItem:
   MsgBox Err.Number & " (" & Err.Description & ") in procedure FindOutlookAppointmentItem of Module Module1"
   Resume Exit_FindOutlookAppointmentItem
   
End Function

Open in new window

0
omgangIT ManagerCommented:
So, the above wasn't exactly what you are looking for.  I modified it a bit so that it searches for the appointment item with the desired value

This is the output now

?FindOutlookAppointmentItem()
 148
This is the message I'm looking for
False

Public Function FindOutlookAppointmentItem() As Boolean

On Error GoTo Err_FindOutlookAppointmentItem

    Dim olOutlook As New Outlook.Application
    Dim olNS As Outlook.Namespace
    Dim olCalendar As Outlook.MAPIFolder
    Dim olCalItem As Outlook.AppointmentItem
    Dim olProp As Object
    
    Set olNS = olOutlook.GetNamespace("MAPI")
    
    Set olCalendar = olNS.GetDefaultFolder(olFolderCalendar)
    
    Debug.Print olCalendar.Items.Count
    
    For Each olCalItem In olCalendar.Items
        'If olCalItem.Subject = "Dalton - presentation" Then
            'olCalItem.ItemProperties.Add "GAID", olText, True
            'olCalItem.ItemProperties.Item("GAID").Value = "Testing"
            'olCalItem.Save
            
        '    For Each olProp In olCalItem.ItemProperties
        '        Debug.Print olProp.Name
        '        If olProp.Name = "GAID" Then
        '            Debug.Print " ----- Value = " & olProp.Value
        '        End If
        '    Next olProp
        'End If
        'Exit For
        
        For Each olProp In olCalItem.ItemProperties
            If olProp.Name = "GAID" Then
                If olProp.Value = "Testing" Then
                    'do something here
                    Debug.Print "This is the message I'm looking for"
                End If
            End If
        Next
        
    Next

Exit_FindOutlookAppointmentItem:
        'destroy object variables
    Set olCalendar = Nothing
    Set olNS = Nothing
   Exit Function

Err_FindOutlookAppointmentItem:
   MsgBox Err.Number & " (" & Err.Description & ") in procedure FindOutlookAppointmentItem of Module Module1"
   Resume Exit_FindOutlookAppointmentItem
   
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.