12.7 Putting it all together

Putting it all together

Listing 5 shows a program that adds an appointment to the calendar, adds several related tasks, then sends an e-mail to the other participants in the meeting, in this case, all the TasTrade employees. The program expects them to be in the Outlook address book however, it produces a message box showing the list of everyone to whom it was unable to send a message. (Like the other e-mail example in this chapter, you need to substitute people who are actually in your Outlook address book for this example to run correctly.) Figure 3 shows the appointment the program sets up, while Figure 4 shows one of the resulting tasks. You ll find Listing 5 as OutlookSample.PRG in the Developer Download files available at www.hentzenwerke.com.

Listing 5. Plan a meeting. This program sets up a meeting by adding it to the calendar, adding several tasks, and sending an e-mail to all employees.

#DEFINE olMailItem 0

#DEFINE olAppointmentItem 1

#DEFINE olTaskItem 3

#DEFINE CR CHR(13)

#DEFINE olImportanceHigh 2

#DEFINE MB_ICONINFORMATION 64 && Information message

#DEFINE MB_OK 0 && OK button only

#DEFINE OneDayInSeconds 86400

LOCAL oNameSpace, oMessage, oAppt, oTask

IF VarType(oOutlook) <> "O"

* Start or connect to Outlook

* Make it public for demonstration purposes.

RELEASE oOutlook

PUBLIC oOutlook

oOutlook = CreateObject("Outlook.Application")

ENDIF

oNameSpace = oOutlook.GetNameSpace("MAPI")

* First, set up the appointment

oAppt = oOutlook.CreateItem( olAppointmentItem )

WITH oAppt

.Subject = "Monthly Staff Meeting"

.Location = "Conference Room A"

.Start = {^ 2000/02/01 9:00}

.Duration = 90

.ReminderSet = .T.

.ReminderMinutesBeforeStart = 15

.Save()

ENDWITH

* Now, set up some associated tasks

* First, the agenda

oTask = oOutlook.CreateItem( olTaskItem )

WITH oTask

.Subject = "Staff Meeting Agenda"

.DueDate = {^ 2000/01/31 12:00}

.Categories = "Staff Meeting"

* get a reminder one day before it's due

.ReminderSet = .T.

.ReminderTime = .DueDate - OneDayInSeconds

.Save()

ENDWITH

* Next, the snacks

oTask = oOutlook.CreateItem( olTaskItem )

WITH oTask

.Subject = "Order refreshments"

.DueDate = {^ 2000/01/30 17:00}

.Categories = "Staff Meeting"

* get a reminder half an hour ahead

.ReminderSet = .T.

.ReminderTime = .DueDate - 30*60

* Put the information about what and where to order in the task

.Body = "Get bagels and danish from the kosher bakery"

.Save()

ENDWITH

* Finally, send a notice out to all employees

OPEN DATA _SAMPLES + "TasTrade\Data\TasTrade"

USE Employee

* Create a cursor to keep track of the employees we were unable to mail to

CREATE CURSOR EmailProbs (cFullName C(40))

oMessage = oOutlook.CreateItem( olMailItem )

WITH oMessage

.Subject = "Monthly Staff Meeting"

.Body = "The monthly staff meeting will be held on " + ;

"Tuesday, February 1 at 9:00 A.M. " + ;

"in Conference Room A. Everyone is expected to attend." + ;

+ CR + CR + ;

"Please bring your sales reports for December and " + ;

"preliminary figures for January." + ;

+ CR + CR + ;

"Refreshments will be served, as usual."

.Importance = olImportanceHigh

* Now loop through Employee, adding recipients

SELECT Employee

SCAN

oRecipient = .Recipients.Add( First_Name - (" " + Last_Name ) )

IF NOT oRecipient.Resolve()

* Either this name is ambiguous or there's no

* e-mail address for this person on file.

* Log the omission

INSERT INTO EmailProbs VALUES (oRecipient.Name)

* Remove this person

oRecipient.Delete()

ENDIF

ENDSCAN

IF .Recipients.Count > 0

* Send it

.Send()

ELSE

* No recipients, so get rid of the message

.Delete()

ENDIF

ENDWITH

* Report the failed e-mails

SELECT EmailProbs

IF RECCOUNT() = 0

MESSAGEBOX( "All e-mails sent", ;

MB_ICONINFORMATION+MB_OK, ;

"Outlook Automation Sample")

ELSE

* Build a string containing the list of failures

cFailString = ""

SCAN

cFailString = cFailString + cFullName + CR

ENDSCAN

MESSAGEBOX("E-mail was not sent to the following employees: " + ;

CR + cFailString, ;

MB_ICONINFORMATION+MB_OK, ;

"Outlook Automation Sample")

ENDIF

USE IN EmailProbs

USE IN Employee

RETURN

Outlook is a rich program for managing personal data, such as schedules, "to do" lists, address books, and e-mail. While its object model is not polymorphic with the rest of Office, it provides plenty of opportunities for Automation.

Figure 3. Automated scheduling. This appointment was added to the calendar by the program in Listing 5.

Figure 4. Tell me what to do. This is one of two tasks created by Listing 5.

Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved



Microsoft Office Automation with Visual FoxPro
Microsoft Office Automation with Visual FoxPro
ISBN: 0965509303
EAN: 2147483647
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net