ACC: How to Add Appointments to Schedule+ using Automation

Last reviewed: September 3, 1997
Article ID: Q149078
The information in this article applies to:
  • Microsoft Access version 7.0, 97

SUMMARY

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

This article demonstrates how to add appointments automatically to Microsoft Schedule+ for Windows 95 using 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 example described below 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, which runs a custom Visual Basic for Applications procedure. The code uses Automation to connect with 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. Create a new form based on the Conferences Sessions table using the AutoForm: Tabular Wizard.

  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. Once logged on, the AddAppts() function creates four new appointments for you using 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 : AutoGnrl kbinterop IntpOleA
Technology : kbole
Version : 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.