Microsoft KB Archive/149078

= ACC: How to Use Automation to Add Appointments to Schedule+ =

Article ID: 149078

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 Q149078



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

This article shows you how to use Automation to add appointments automatically to Microsoft Schedule+ for Windows 95.

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 example in this article creates a table for storing appointment information, such as date, start time, end time, and a brief description. Then, it creates a form with a command button that runs a custom Visual Basic for Applications procedure. The code uses Automation to connect to Microsoft Schedule+ and to create new appointments using information stored in the table.

To add appointments to Microsoft Schedule+, follow these steps:

  Create a new table in Design view with the following structure:       Table: Conference Sessions --      Field Name: Session Data Type: Text Field Name: Date Data Type: Text Field Name: Start Time Data Type: Text Field Name: End Time Data Type: Text   Save the table as Conference Sessions. Switch to Datasheet view and add the following four records:     Session                                  Date    Start Time  End Time -    DMT408:Distributing Access Applications  4/16/96   11:30 AM   1:00 PM     OFC307:Overview of Office Object Models  4/16/96    9:30 AM  11:30 AM     OFC401:Performance Optimization          4/17/96    2:30 PM   4:30 PM     OFC406:Access External Data              4/18/96   11:30 AM   1:00 PM  Use the AutoForm: Tabular Wizard to create a new form based on the Conferences Sessions table. Switch the form to Design view. Select the form footer and set its Height property to .5 inches. Add a command button to the form footer with the following properties:

Name: AddAppt

Caption: Add Appointments

OnClick: =AddAppts

</li> On the View menu, click Code to open the form module.</li>  In the General section of the module, add the following procedure: Function AddAppts On Error GoTo Command1_Click_error

Dim objApp As Object, objSched As Object Dim objTable As Object, objItem As Object Dim db As DATABASE, rs As Recordset, i As Integer, UserName As _ String Dim startDateTime As Variant, endTime As Variant, apptText As _ Variant

' Connect to Schedule+ and check if user is logged on or not ' logged on. Set objApp = CreateObject("SchedulePlus.Application") If Not objApp.LoggedOn Then UserName = InputBox("Please enter your profile name." & _                          Chr(13) & Chr(13) & "Example: Nancy Davolio") If UserName = "" Then Set objApp = Nothing Exit Function End If               objApp.Logon UserName, " ", True End If         Set objSched = objApp.ScheduleLogged Set objTable = objSched.SingleAppointments

' Create a recordset from the Conference Sessions table. Set db = CurrentDb Set rs = db.OpenRecordset("Conference Sessions")

' Loop through recordset and retrieve values for appointments. For i = 0 To rs.RecordCount - 1 startDateTime = rs!Date & " " & rs![start time] endTime = rs!Date & " " & rs![end time] apptText = rs!session

' Create a new appointment and set its properties. Set objItem = objTable.New objItem.SetProperties Text:=apptText, _ BusyType:=CLng(1), Start:=CDate(startDateTime), _ End:=CDate(endTime)

rs.MoveNext Next I

' Log off Schedule+ and release the objects. objApp.logoff Set objApp = Nothing Set objSched = Nothing Set objItem = Nothing Set objTable = Nothing

MsgBox i & " appointments were added to Schedule+." Exit Function

Command1_Click_error: If Err = -2147221229 Or Err = 5 Or Err = 3270 Then MsgBox "Operation canceled." Else MsgBox "Error: " & Err & " " & Error End if         Exit Function

End Function </li> Close the form module and switch the form to Form view.</li> Click the Add Appointments button to create appointments in Microsoft Schedule+. If you are not currently logged on to Microsoft Schedule+, you are asked for your profile name. After you've logged on, the AddAppts function creates four new appointments for you, using the information stored in the Conference Sessions table.</li></ol>

<div class="references_section">