Probably the most used Microsoft Office Application is Outlook. Often Outlook is open all day to receive emails,
schedule appointments, and manage Contact information. Unfortunately, it is not always easy to share data
between Outlook and Access.
If you use an Access Database that stores almost any kind of dates such as shipping dates, appointments,
service scheduling, and maintenance schedules you may wish you could save that information to the Outlook
Calendar with just the click of a button.
In this article, we will show you how to do just that. We will show you how to add data from an
Access Form to an Outlook Calendar Appointment with just one mouse click.
One of the best things about this method is its flexibility. You can create an Access Form that holds the
precise data you want to save to Outlook. We have set up a Table and Form to hold the Appointment Information
we want. Yours can be set up differently. You may use a maintenance schedule, client appointments, project
progress dates, or almost any kind of information with a date.
We can add an Appointment to the Outlook Calendar with just one click on our Form’s "Add Appt to Outlook" Link button.
Let us look at the code behind that button. First we need to make sure the Current Record is saved. If a Form
is "Dirty" that means there has been a change made to the data on the Form, but it has not yet been saved. In
order for Access to make the Form "Dirty = False" it has to save the current data on the Form.
Next, we check to make sure the appointment has not already been added to Outlook. On our form we have a checkbox
that indicates if that has been done. If the appointment already exists, we inform the user and Exit the Sub.
We are using "late binding" so our code works in almost all versions of Outlook. This is crucial
if you distribute your Database or take it with you in your thumb drive to use on other computers. However, one
drawback of using late binding is that it is slower than early binding. With late binding we use an Object variable:
This is how we would do it if we were using "early binding":
We need to know if Outlook is already open because there are two methods of instantiating Outlook and other Office
Applications. You use the CreateObject Function if Outlook is not open, and you use the
GetObject Function if Outlook is already open.
To determine if Outlook is open we are using the isAppThere Custom Function which we have included
at the end of this article. This Function returns True if the application is open, and
False if it is not open.
An Outlook Appointment is called an Item, and is referenced in Outlook as olAppointmentItem;
its constant value is 1. We must use the value 1 in order to create the Appointment Item so we put the 1 in parentheses after
"CreateItem". With late binding, we must use the numbers. In early binding, we could have put olAppointmentItem
in the parentheses.
To create a new Appointment Item we use the CreateItem Function instead
of the CreateObject Function.
Our example adds data from the Form to Outlook Appointment Properties. Your Fields and Form Controls probably
will not have the same names as the Outlook Appointment Properties. This is no problem because you can easily manage that
difference in code. For example, if you have a TextBox named "txtProjectDueDate". You can use that as your Outlook "Start"
Property like this:
You may need to use more Appointment Properties than we have in our example. You can use the Object Browser
to see the complete list of Appointment Properties. It is a long list with more than enough Properties to meet almost anyone's needs.
Now let us examine how to add our data to the Appointment Properties:
"Start" is the first Appointment Property we are setting. Outlook uses both the Date and Time in the Start Property,
but our Form has the date and time in seperate TextBoxes. To handle this, we just concatenate the date and time together
In order to avoid errors, we will use the Nz
Function to handle nulls and zero length strings in our TextBoxes or
ComboBoxes. The Nz Function gets the value you designate if the value is Null or a Zero Length String after the comma
like this: Nz(Me.myTextBox, 0). This will not change the value in the TextBox, but it will
change the value in the code.
Outlook does not require that the time be added to the Start Property. However, to avoid errors, if you leave the Start Time blank, then you need to leave the End Time blank also. You can do this if you just want to add the due date for a project without the Time.
The Outlook Appointment Property "End" is not always required but you may get an error if you do not supply any value.
Here we are using the Nz Function to provide a 0 value in case the txtApptLength TextBox is Null.
We have provided a Combo box to select Locations from a Table to add to our Form along with other information about
the location in unbound TextBoxes. Here we add the Outlook Location Property.
If we want Outlook to Remind us when our appointment is near we check the chkAppointReminder Checkbox on our Form
and enter the number of minutes we want to be reminded before our Appointment. If the chkAppointReminder Checkbox
is checked but we forget to enter our reminder minutes it will cause an error. To avoid that error we use code to
change no minutes to 30 minutes.
Now we can save the Appointment Properties and start cleaning up:
Here is the code by Rick Dobson that checks if Outlook is open.
We have shown you how you can transfer Calendar data from Access to Outlook with just one mouse click using the
Appointments Database. With just a little modification of the code, you can use your present Forms to send information
with Dates to the Outlook Calendar.
Get the Code
You can download the code used in this article from our
Free Code Samples page
or you can purchase the
Access and Outlook Appointment Manager.
We use Microsoft Azure SQL Databases to provide safe and affordable 24/7 internet access to your company's vital information.
Contact us for a Free Consultation, feedback, or more information:
Page layouts based on Matthew James Taylor's Perfect multi-column CSS liquid layouts