May 31st, 2002, 10:26 AM
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?
May 31st, 2002, 10:40 AM
Dim myOlApp As New Outlook.Application
Dim myAppt As AppointmentItem
Dim myNS As NameSpace
Dim myAppts As Items
Dim strTheDay As String
Dim strToday As String
Dim strMsg As String
Dim strEndDay As String
Dim rstData As Recordset
Set rstData = gdbs.openrecordset("Data")
strTheDay = Format(MaskEdBox1.Text, "dd/mm/yyyy")
strEndDay = Format(MaskEdBox2.Text, "dd/mm/yyyy")
'specify the range
strToday = "[Start] >= '" & strTheDay & _
"' and [Start] < '" & strEndDay & " 11:59pm '"
'Get user's appointments from Calendar folder
Set myNS = myOlApp.GetNamespace("MAPI")
Set myAppts = myNS.GetDefaultFolder(olFolderCalendar).Items
'sort the collection (required by IncudeRecurrences).
'Make sure recurring appointments are included
myAppts.IncludeRecurrences = True
'filter the collection to include only the day's appointments.
Set myAppts = myAppts.Restrict(strToday)
'Sort again to put recurring appointments in correct order.
'Loop through collection and get subject, start time, location and Busystatus of each time
Set myAppt = myAppts.GetFirst
Do While TypeName(myAppt) <> "Nothing"
rstData!Subject = myAppt.Subject
rstData!Location = myAppt.Location
rstData!Date = Format(myAppt.start, "dd/mm/yyyy")
rstData!busystatus = myAppt.busystatus
Set myAppt = myAppts.GetNext
Set myOlApp = Nothing
Set myAppt = Nothing
Set myNS = Nothing
Set myAppts = Nothing
May 31st, 2002, 11:49 AM
That looks perfect - thanks very much
Click Here to Expand Forum to Full Width