PDA

View Full Version : Outlook VBA validate appointment



cornall
11-04-2008, 09:22 AM
Can I use VBA to validate an appointment and check if the status is set to busy when the user clicks save? If the time is set to free it should pop up a warning.

JP2112
11-05-2008, 01:03 PM
Can you maybe provide a specific example?

Do you want to check someone else's free/busy time?

--JP


Can I use VBA to validate an appointment and check if the status is set to busy when the user clicks save? If the time is set to free it should pop up a warning.

cornall
11-06-2008, 01:39 AM
To be more specific,

We have various calendars in outlook representing company resources e.g. laptops.

Our users book time against these resources by setting up appointments/meetings and adding the resource as a required attendee.

A "feature" of Outlook is that when you set an appointment to be an all day event the free busy time reverts to Free. This means other users can double book the resource. It happens often as users dont check the calendar of the resource they just add the resource as an attendee.

As I couldn't find a way to do it using VBA I have written a C# application which checks the shared calendars every x hours and e-mails the orginizer if the resource has been booked as free.

I was wondering if there was a way to aleart the user to the fact that the free/busy time has reverted to free at runtime using VBA?

Cheers D

JP2112
11-06-2008, 08:25 AM
You can set up some event code in VBA that checks every new appointment to see if it is an All Day Event. If so, it sets the olBusyStatus to olBusy. But you can't set the resource to "busy" that way --you have to schedule it as a resource, not an attendee, because nobody is on the other end to "accept" the appointment.

When you create a new meeting request (I press Ctrl-Shift-Q in Outlook 2003), click the "To" button, scroll to the resource you want to use (conference room, projector, etc) and click the "Resources" button at the bottom of the dialog box.

Now, if the resource is already booked during that time, you should get a message to that effect.

Here's the sample code for the end user to check if an appointment they are adding is an All Day Event marked "Free."



Private WithEvents MyItems As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
Set MyItems = objNS.GetDefaultFolder(olFolderCalendar).Items
End Sub
Private Sub MyItems_ItemAdd(ByVal item As Object)
Dim Appt As Outlook.AppointmentItem
If TypeOf item Is Outlook.AppointmentItem Then
Set Appt = item
With Appt
If .AllDayEvent Then
.BusyStatus = olBusy
.Save
End If
End With
End If
End Sub





To be more specific,

We have various calendars in outlook representing company resources e.g. laptops.

Our users book time against these resources by setting up appointments/meetings and adding the resource as a required attendee.

A "feature" of Outlook is that when you set an appointment to be an all day event the free busy time reverts to Free. This means other users can double book the resource. It happens often as users dont check the calendar of the resource they just add the resource as an attendee.

As I couldn't find a way to do it using VBA I have written a C# application which checks the shared calendars every x hours and e-mails the orginizer if the resource has been booked as free.

I was wondering if there was a way to aleart the user to the fact that the free/busy time has reverted to free at runtime using VBA?

Cheers D