Convert the text Priority value to a number for Outlook.
strPriority = Nz(![Priority])
lngPriority = Switch(strPriority = “(1) High”, _
1, strPriority = “(2) Normal”, 2, _
strPriority = “(3) Low”, 3, _
“”, 0)
strDescription = Nz(![Description])
Create a new task item in the selected Tasks folder.
Set tsk = fldTasks.Items.Add
tsk.Subject = strTaskName
tsk.StartDate = dteStartDate
tsk.DueDate = dteDueDate
tsk.Status = lngStatus
tsk.Body = strDescription
tsk.PercentComplete = Nz(![% Complete])
tsk.Close (olSave)
NextTask:
.MoveNext
Loop
End With
MsgBox “Tasks exported to Outlook”
ErrorHandlerExit:
Exit Function
ErrorHandler:
Outlook is not running; open Outlook with CreateObject.
If Err.Number = 429 Then
Set appOutlook = CreateObject(“Outlook.Application”)
Resume Next
Else
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End If
End Function
Figure 8.24 shows the exported tasks in the Tasks folder (in Outlook 2007, this folder is now
called the To Do List).
Working with Outlook Items 8