Access.2007.VBA.Bibl..

(John Hannent) #1
FIGURE 8.24
Tasks in the Outlook To Do List exported from an Access table.

To import tasks from your local Outlook Tasks folder into an Access table (tblImportedTasks), use
the following function (it can also be run from the mcrImportTasksFromOutlook macro):

Public Function ImportTasksFromOutlook
On Error GoTo ErrorHandler

Dim fldTasks As Outlook.Folder
Dim tsk As Outlook.TaskItem
Dim strTaskName As String
Dim dteStartDate As Date
Dim dteDueDate As Date
Dim strStatus As String
Dim lngStatus As Long
Dim strPriority As String
Dim lngPriority As Long
Dim strDescription As String
Dim lngPercentComplete As Long
Dim itm As Object
Dim strSQL As String

Set appOutlook = GetObject(, “Outlook.Application”)
Set nms = appOutlook.GetNamespace(“MAPI”)
Set fldTasks = nms.GetDefaultFolder(olFolderTasks)

Clear table of old data.

strSQL = “DELETE * FROM tblImportedTasks”
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(“tblImportedTasks”)

Iterate through tasks in the Tasks folder and import them to the Access table.

For Each itm In fldTasks.Items
If itm.Class = olTask Then
Set tsk = itm

Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf