Using Solutions::PIM Controls with the MS Outlook Appointments Collection


You may use the controls found in DBI's Solutions::PIM to create your own custom forms that tie into MS Outlook data. However, in order to do so, the host language must be able to access the "MS Outlook Object Library".

 

NOTE : Greater detail on a description of the Outlook object model and how it works may be found at the Microsoft web site and downloading the help file that describes accessing the Outlook objects (VBAOUTL.hlp). We also found the book "Building Applications with MS Outlook 98 (ISBN 1-57231-718-3) to be helpful.

 

Using the Outlook Object Model

Before you can access the data from Outlook, you must include a reference to the MS Outlook Object Library (MSOUTL8.olt and MSOUTL8.olb).

 

Microsoft Visual Basic : From the main menu, select Project -> References. Then select the title "Microsoft Outlook 8.0 Object Library".

 

Microsoft Access : You must first display a code window. Once displayed, select Tools->Preferences from the main menu. From there, select the title "Microsoft Outlook 8.0 Object Library".

 

Obtaining the Appointment Folder

MS Outlook organizes its data into a series of different folders. These folders are set up as collections (arrays of objects). In our case, we want to access the Appointment folder. To do so, we must first set up the variables to accept the data.

 

The following code was placed in the general declaration section of the host form. Please note that the following code is written in VBA:

 

Public olApplication As Outlook.Application

Public olNamespace As NameSpace

Public olAppFolder As MAPIFolder

Public olAppointments As Items

 

The next piece of code was then placed in the "Load" event of the host form:

 

Set olApplication = CreateObject("Outlook.Application")

Set olNamespace = olApplication.GetNamespace("MAPI")

Set olAppFolder = olNamespace.GetDefaultFolder(olFolderCalendar)

Set olAppointments = olAppFolder.Items

 

The variable olAppointments now contains a collection of all appointments

 

Working with the Appointments Collection

Now that we have our collection of appointments, we will use it to populate the controls from Solutions::PIM.

 

1. The following code places all the appointments into the ctMDay (multi-column day view) control.

Dim i As Integer

    Dim nIndex As Integer

    Dim lDate As Long

    Dim nSMinute As Integer

    Dim nSHour As Integer

    Dim nEMinute As Integer

    Dim nEHour As Integer

   

    For i = 1 To olAppointments.Count

        lDate = olAppointments.Item(i).Start

        nSMinute = Minute(olAppointments.Item(i).Start)

        nEMinute = Minute(olAppointments.Item(i).End)

        nSHour = Hour(olAppointments.Item(i).Start)

        nEHour = Hour(olAppointments.Item(i).End)

        

        If (nSHour < 12) Then

            lDate = lDate + 1

        End If

        

        nIndex = ctMDay1.AddKeyAppointment((nSHour * 60) + nSMinute, (nEHour * 60)_

+ nEMinute, lDate, olAppointments.Item(i).Subject,_ olAppointments.Item(i).EntryID)

        ctMDay1.AppointLocateText(nIndex) = olAppointments.Item(i).Location

        ctMDay1.AppointItemData(nIndex) = olAppointments.Item(i).Body

        ctMDay1.AppointRemindIcon(nIndex) = olAppointments.Item(i).ReminderSet

    Next

2. The following code segment places appointment information into the ctMonth calendar object.

 

    Dim cString As String

    Dim myItem As Items

    Dim vSDate As Date

    Dim vEDate As Date

    Dim nCntr As Integer

    Dim lDate As Long

    Dim nHour As Integer

    Dim nDay As Integer

    

    vSDate = ctMonth1.BaseDate(1)

    vEDate = ctMonth1.BaseDate(2)

    cString = "[Start] >= '" + Str(vSDate) + "' AND [Start] <= '" + Str(vEDate) + "'"

    Set myItem = w_Main.olAppointments.Restrict(cString)

    

    If myItem.Count > 0 Then

        For nCntr = 1 To myItem.Count

            lDate = myItem.Item(nCntr).Start

            nHour = Hour(myItem.Item(nCntr).Start)

        

            If (nHour < 12) Then

                lDate = lDate + 1

            End If

            

            nDay = ctMonth1.DateInMonth(lDate)

            

            If (nDay > 0) Then

                If (Len(ctMonth1.DateText(nDay)) = 0) Then

                    ctMonth1.DateText(nDay) = myItem.Item(nCntr).Subject

                ElseIf (Len(ctMonth1.DateText2(nDay)) = 0) Then

                    ctMonth1.DateText2(nDay) = myItem.Item(nCntr).Subject

                ElseIf (Len(ctMonth1.DateText3(nDay)) = 0) Then

                    ctMonth1.DateText3(nDay) = myItem.Item(nCntr).Subject

                Else

                    ctMonth1.DatePicture(nDay) = 1

                End If

            End If

        Next

    End If

 

Common Properties used with MS Outlook and the Solutions::PIM Controls

Many properties of Solutions::PIM controls are similar to those of the MS Outlook Appointments collection. This simplifies the movement of data back and forth between the Outlook database and DBI's controls. While there are also properties within the Appointments collection that cannot be used by DBI's controls, you can use your own custom dialog forms to access any piece of the Appointments collection data that does not relate to a DBI control.

 

The following table displays some of the properties of the MS Outlook Appointments collection as they relate to the DBI controls ctMDay and ctMonth. Please note that the following table is a suggested list.

 

 

Appointments

ctMonth.OCX

ctMDay.OCX

EntryID

None

AppointKeyID

Subject

DateText

DateText2

DateText3

AppointText

Location

DatePicture

AppointLocateText

AppointLocateIcon

Body

DateText2

DateText3

AppointItemData

Start

Date

AppointDate

AppointTimeStart

End

Date

AppointDate

AppointTimeEnd

ReminderSet

DatePicture

AppointRemindIcon