Loop through future appointments

G

Guest

Hello,

I am trying to develop a routine, to be used from access, to loop through
all the future (today moving forward, not interested in past appt)
appointments in my outlook calendar and then extracting the info from each
appt. Could someone get me started or point me to an example, website...?

Thank you for the guidance,

Daniel P
 
G

Guest

Try the code below, but first make sure you have a reference set to the
Microsoft Outlook Object Model in your Access VBA Project:

Sub GetUpcomingAppointments()
On Error GoTo GetUpcomingAppointments_Error

Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objCalendarFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim objAppt As Outlook.AppointmentItem

Set objOL = New Outlook.Application
Set objNS = objOL.GetNamespace("MAPI")
Set objCalendarFolder = objNS.GetDefaultFolder(olFolderCalendar)
Set objItems = objCalendarFolder.Items.Restrict("[Start] >= '" &
Format(Date, "ddddd h:nn AMPM") & "'")

For Each objAppt In objItems
Debug.Print objAppt.Subject & " (Start: " & objAppt.Start & "; End:
" & objAppt.End
Next

Set objOL = Nothing
Set objNS = Nothing
Set objCalendarFolder = Nothing
Set objAppt = Nothing
Set objItems = Nothing

On Error GoTo 0
Exit Sub

GetUpcomingAppointments_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
GetUpcomingAppointments of Module basCalendarReports"
Resume Next
End Sub
 
G

Guest

Thank you Eric!

It works perfectly! Thank you for your time and help once again.

Daniel P




Eric Legault said:
Try the code below, but first make sure you have a reference set to the
Microsoft Outlook Object Model in your Access VBA Project:

Sub GetUpcomingAppointments()
On Error GoTo GetUpcomingAppointments_Error

Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objCalendarFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim objAppt As Outlook.AppointmentItem

Set objOL = New Outlook.Application
Set objNS = objOL.GetNamespace("MAPI")
Set objCalendarFolder = objNS.GetDefaultFolder(olFolderCalendar)
Set objItems = objCalendarFolder.Items.Restrict("[Start] >= '" &
Format(Date, "ddddd h:nn AMPM") & "'")

For Each objAppt In objItems
Debug.Print objAppt.Subject & " (Start: " & objAppt.Start & "; End:
" & objAppt.End
Next

Set objOL = Nothing
Set objNS = Nothing
Set objCalendarFolder = Nothing
Set objAppt = Nothing
Set objItems = Nothing

On Error GoTo 0
Exit Sub

GetUpcomingAppointments_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
GetUpcomingAppointments of Module basCalendarReports"
Resume Next
End Sub

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Daniel said:
Hello,

I am trying to develop a routine, to be used from access, to loop through
all the future (today moving forward, not interested in past appt)
appointments in my outlook calendar and then extracting the info from each
appt. Could someone get me started or point me to an example, website...?

Thank you for the guidance,

Daniel P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top