Microsoft KB Archive/160502

= ACC: Using Automation to Add Appointments to Microsoft Outlook =

Article ID: 160502

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q160502



Advanced: Requires expert coding, interoperability, and multiuser skills.



SUMMARY
This article shows you how to use Automation to create appointments in a Microsoft Access database and how to add them to the Microsoft Outlook calendar.

For information about using Automation to add an appointment to Microsoft Schedule+ for Windows 95, please see the following article in the Microsoft Knowledge Base:

149078 ACC: How to Add Appointments to Schedule+ using OLE Automation

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.



MORE INFORMATION
The following example demonstrates how to create a form and a table to enter and store appointment information in a Microsoft Access database, and provides a sample Visual Basic for Applications procedure that uses Automation to add your appointments to Microsoft Outlook.  Start Microsoft Access and create a new database called Appt.mdb.  Create the following new table in Design view:      Table: tblAppointments --     Field Name: Appt Data Type: Text Field Size: 50 Required: Yes Field Name: ApptDate Data Type: Date/Time Format: Short Date Required: Yes Field Name: ApptTime Data Type: Date/Time Format: Medium Time Required: Yes Field Name: ApptLength Data Type: Number Field Size: Long Integer Default Value: 15 Required: Yes Field Name: ApptNotes Data Type: Memo Field Name: ApptLocation Data Type: Text Field Size: 50 Field Name: ApptReminder Data Type: Yes/No Field Name: ReminderMinutes Data Type: Number Field Size: Long Integer Default Value: 15 Field Name: AddedToOutlook Data Type: Yes/No

Table Properties: tblAppointments -     PrimaryKey: ApptDate;ApptTime NOTE: In this example, the primary key in the appointment table is the appointment date and time. You can remove or alter the primary key if you want to be able to add multiple appointments for the same date and time.  Create a reference to the Microsoft Outlook 8.0 Object Library. To do so, follow these steps:  Create a new module. On the Tools menu, click References. Click Microsoft Outlook 8.0 Object Library in the Available References box. If that reference does not appear, click Browse to locate the Msoutl8.olb file, which is installed by default in the C:\Program Files\Microsoft Office\Office folder.</li> Click OK in the Reference dialog box.</li> Close the module without saving it.</li></ol> </li> Use the AutoForm: Columnar Form Wizard to create a new form based on the tblAppointments table. Save the form as frmAppointments.</li>  Open the form in Design view and change the following properties: <pre class="fixed_text">     Form: frmAppointments -     Caption: Appointment Form

Form Header: Height: .5"     Check Box: AddedToOutlook         Enabled: No                        </li>  Add a command button to the Form Header section, and set the following properties: <pre class="fixed_text">      Command Button:         Name: AddAppt         Caption: Send to Outlook         OnClick: [Event Procedure]                        </li>  Set the OnClick property of the command button to the following event procedure:       Private Sub AddAppt_Click         On Error GoTo AddAppt_Err         ' Save record first to be sure required fields are filled.         DoCmd.RunCommand acCmdSaveRecord         ' Exit the procedure if appointment has been added to Outlook.         If Me!AddedToOutlook = True Then            MsgBox "This appointment already added to Microsoft Outlook"            Exit Sub         ' Add a new appointment.         Else            Dim outobj As Outlook.Application Dim outappt As Outlook.AppointmentItem Set outobj = CreateObject("outlook.application") Set outappt = outobj.CreateItem(olAppointmentItem) With outappt .Start = Me!ApptDate & " " & Me!ApptTime .Duration = Me!ApptLength .Subject = Me!Appt If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes If Not IsNull(Me!ApptLocation) Then .Location = _ Me!ApptLocation If Me!ApptReminder Then .ReminderMinutesBeforeStart = Me!ReminderMinutes .ReminderSet = True End If              .Save End With End If        ' Release the Outlook object variable. Set outobj = Nothing ' Set the AddedToOutlook flag, save the record, display a message. Me!AddedToOutlook = True DoCmd.RunCommand acCmdSaveRecord MsgBox "Appointment Added!" Exit Sub AddAppt_Err: MsgBox "Error " & Err.Number & vbCrLf & Err.Description Exit Sub End Sub </li> Save the form and open it in Form view. Add an appointment record, and then click the Send To Outlook button. Be sure you only enter minutes, not hours and minutes, in the ApptLength field.</li> Start Microsoft Outlook and click Calendar on the Go menu to view the appointments you added.</li></ol>

Additional query words: integrate meeting OLE OutSol OutSol97

Keywords: kbfaq kbhowto kbinterop kbprogramming KB160502

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.