The below code can be placed into the “OnClick” Event of a generic button on any form. Each of the inserted variables can be exchanged for a control value of equal type in any manner supported by VBA/SQL. Make sure to create a Reference to Microsoft Outlook 9.0 Object Library (MS Access 2000), or Microsoft Outlook 8.0 Object Library (MS Access 97).
Tim Bankerd
Custom Designed Database Applications
wwg@fdn.com
The WorldWide Group of Online Services
—-Working Code Start—-
Private Sub Set_Up_A_Task_Click()
‘This will start an instance of Outlook
Dim olApp As Outlook.Application
Set olApp = CreateObject(“Outlook.Application”)
‘The following Dim’s are to set Outlook variables
Dim otTask As TaskItem
Dim ofFolder As MAPIFolder
Dim onNamespace As NameSpace
Dim ofInbox As MAPIFolder
Dim oicItems As Items
Dim omMail As MailItem
Dim orpRecurrence As RecurrencePattern
‘This block creates a new Task Record in Outlook
Set onNamespace = GetNamespace(“MAPI”)
Set ofInbox = onNamespace.GetDefaultFolder(olFolderInbox)
Set ofFolder = onNamespace.GetDefaultFolder(olFolderTasks)
Set otTask = ofFolder.Items.Add
‘This is the Subject Line of the Task
otTask.Subject = “This is the Task Subject Line”
‘This will create the entire body of the Task. Make sure to use SQL formatting for all of the Syntax
otTask.Body = “This should be the task itself.” & “This should be the second line of the Task.”
otTask.ReminderSet = True
otTask.ReminderTime = Date & ” ” & Format(Time + 1 / 24, “hh:mm:ss”)
otTask.ReminderOverrideDefault = True
otTask.ReminderSoundFile = “F:MSOffice2000OfficeReminder.wav”
otTask.ReminderPlaySound = True
otTask.Sensitivity = olConfidential
otTask.Assign
otTask.Recipients.Add “Put Email Name Here for each person in the task requirements”
otTask.Recipients.ResolveAll
‘This sets up the recurrance pattern of the Task. In this case
‘it will play the “Reminder.wav” file and present a reminder each day for 14 days.
Set orpRecurrence = otTask.GetRecurrencePattern
orpRecurrence.PatternStartDate = Date + 1
orpRecurrence.PatternEndDate = Date + 14
orpRecurrence.RecurrenceType = olRecursDaily
‘This sends the Task to Outlook
otTask.Send
End Sub
—-Working Code End—-