Finding current appointment in Outlook-VBForums
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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334
    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
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.