Results 1 to 3 of 3

Thread: Finding current appointment in Outlook

  1. #1
    aidan
    Guest

    Finding current appointment in Outlook

    I want my VB app to check what a particular person is doing at a particular time by looking in their Outlook calendar. I can get the appointments out, but there might be 100s, and some might be recurring, so it is a real drag to do this myself. Is there any easier way to pick out any appointments which coincide with a certain date and time?

    Thanks

    Aidan

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this
    VB Code:
    1. Dim myOlApp As New Outlook.Application
    2. Dim myAppt As AppointmentItem
    3. Dim myNS As NameSpace
    4. Dim myAppts As Items
    5. Dim strTheDay As String
    6. Dim strToday As String
    7. Dim strMsg As String
    8. Dim strEndDay As String
    9. Dim rstData As Recordset
    10.  
    11. Set rstData = gdbs.openrecordset("Data")
    12.  
    13. strTheDay = Format(MaskEdBox1.Text, "dd/mm/yyyy")
    14. strEndDay = Format(MaskEdBox2.Text, "dd/mm/yyyy")
    15.  
    16. 'specify the range
    17.  
    18. strToday = "[Start] >= '" & strTheDay & _
    19. "' and [Start] < '" & strEndDay & " 11:59pm '"
    20.  
    21. 'Get user's appointments from Calendar folder
    22.  
    23. Set myNS = myOlApp.GetNamespace("MAPI")
    24. Set myAppts = myNS.GetDefaultFolder(olFolderCalendar).Items
    25.  
    26. 'sort the collection (required by IncudeRecurrences).
    27.  
    28. myAppts.Sort "[Start]"
    29.  
    30. 'Make sure recurring appointments are included
    31.  
    32. myAppts.IncludeRecurrences = True
    33.  
    34. 'filter the collection to include only the day's appointments.
    35.  
    36. Set myAppts = myAppts.Restrict(strToday)
    37.  
    38. 'Sort again to put recurring appointments in correct order.
    39.  
    40. myAppts.Sort "[Start]"
    41.  
    42. 'Loop through collection and get subject, start time, location and Busystatus of each time
    43.  
    44. Set myAppt = myAppts.GetFirst
    45. Do While TypeName(myAppt) <> "Nothing"
    46. rstData.AddNew
    47. rstData!Subject = myAppt.Subject
    48. rstData!Location = myAppt.Location
    49. rstData!Date = Format(myAppt.start, "dd/mm/yyyy")
    50. rstData!busystatus = myAppt.busystatus
    51. rstData.Update
    52. Set myAppt = myAppts.GetNext
    53. Loop
    54. Set myOlApp = Nothing
    55. Set myAppt = Nothing
    56. Set myNS = Nothing
    57. Set myAppts = Nothing
    58.  
    59. rstData.Close

  3. #3
    aidan
    Guest
    That looks perfect - thanks very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width