How To Check Someone Else's Schedule for Free/Busy Information (186753)



The information in this article applies to:

  • Collaboration Data Objects (CDO) 1.21
  • Collaboration Data Objects (CDO) 1.2

This article was previously published under Q186753

SUMMARY

This article contains sample code that allows you to check someone else's schedule (or a resource account's schedule) programmatically using Collaboration Data Objects (1.2, 1.21) to obtain free/busy information.

NOTE: You do not need any special access permission to see if another user has scheduled Tentative, Busy, Free or Out of Office time.

MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

  1. Open a new Visual Basic standard executable project.
  2. Create a reference to the Microsoft Collaboration Data Objects (1.2, 1.21) Library (Cdo.dll).
  3. Create a Command button named Command1 on the form.
  4. Copy and paste the following code into the form:
          Private Sub Command1_Click()
            Dim ObjSession As MAPI.Session
            Dim ObjMessage As Message
            Dim ObjAddressEntry As AddressEntry
    
            Set ObjSession = CreateObject("mapi.session")
            ObjSession.Logon profilename:="YourProfileName"
            Set ObjMessage = ObjSession.Inbox.Messages.Add
            Set ObjRecipColl = ObjMessage.Recipients
            Set ObjOneRecip = ObjRecipColl.Add
    
            'Type the alias of the person or the resource account.
            ObjOneRecip.Name = "JoeDoe"
            ObjOneRecip.Resolve
            Set ObjAddressEntry = ObjOneRecip.AddressEntry
    
            'Specify the date/time of the beginning of the first time slot.
            StartTime="1998/06/03 8:00:00 AM"
    
            'Specify the date/time of the end of the last time slot.
            EndTime="1998/06/03 10:00:00 AM"
    
            'Specify the length of each time slot in minutes.
            'If Interval parameter is less than 1, GetFreeBusy returns
            'CdoE_INVALID_PARAMETER.
    
            Interval=60
            'Interval parameter determines the number of time slots.
            'For this example, Interval is set to 60 minutes. Therefore,
            'there will be 2 time slots between the StartTime and the EndTime.
            'The first time slot is between 8:00:00-9:00:00 AM.
            'The second time slot is between 9:00:00-10:00:00 AM.
    
            FreeBusy = ObjAddressEntry.GetFreeBusy(StartTime, EndTime, _
              Interval)
            'Since there are two time slots, the GetFreeBusy method returns a
            'string with length 2. For example, FreeBusy = "21" indicates that
            'there is a tentative commitment during the time slot 1. Also,
            'there is a confirmed commitment during the time slot 2.
    
            Msg = ""
            For i = 1 To Len(FreeBusy)
             Select Case Mid(FreeBusy, i, 1)
              Case "0"
               TempMsg = "Available for meetings/appointments during " & _
               "the time slot " & i & vbLf
              Case "1"
                TempMsg = "At least one tentative commitment during " & _
               "the time slot " & i & vbLf
              Case "2": TempMsg = "At least one confirmed commitment " & _
               "during the time slot " & i & vbLf
              Case "3": TempMsg = "Out-of-office (OOF) for at least  " & _
               "part of the time slot " & i & vbLf
             End Select
             Msg = Msg + TempMsg
            Next
            MsgBox Msg
    
            ObjSession.Logoff
            Set ObjMessage = Nothing
            Set ObjRecipColl = Nothing
            Set ObjOneRecip = Nothing
            Set ObjAddressEntry = Nothing
            Set ObjSession = Nothing
          End Sub
    					
  5. Run the project and click Command1. A message box displays free/busy information for each time slot for the selected time frame.

Modification Type:MajorLast Reviewed:6/6/2005
Keywords:kbcode kbhowto kbMsg KB186753