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

ID: Q149078

The information in this article applies to:

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:

 1. 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

 2. 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

 3. Use the AutoForm: Tabular Wizard to create a new form based on the
    Conferences Sessions table.

 4. Switch the form to Design view.

 5. Select the form footer and set its Height property to .5 inches.

 6. Add a command button to the form footer with the following properties:

       Name: AddAppt
       Caption: Add Appointments
       OnClick: =AddAppts()

 7. On the View menu, click Code to open the form module.

 8. 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

 9. Close the form module and switch the form to Form view.

10. 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.

REFERENCES

For information about using Automation to add appointments to Microsoft Outlook, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q160502
   TITLE     : ACC: Using Automation to Add Appointments to Microsoft
               Outlook

For more information about using Automation in Microsoft Access, search the Help Index for "Automation," or ask the Microsoft Access 97 Office Assistant.

Additional query words: OLE

Keywords          : kbinterop IntpOlea 
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto

Last Reviewed: November 21, 1998