Discussion Locked

Add task to Outlook tasklist from Access

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is it possible to assign a task from Access 2000 database program to a tasklist in Microsoft Outlook, before a due date in the program expired. How can it be done?

4 replies

by p7ants

Alec,
Please excuse the brevity. Just cut and paste this into an Access Module. Let me know if more is needed. I am willing to explain as well. Send me an email if you wish.

Phil

Private myOlApp As Object
Private myNameSpace As Object
Private myFolder As Object
Private myItem As Object
Private boolCreate As Boolean
'

Public Function AddOLTask(snote As String, sSub As String, dStDt As Date) As Boolean

snote = snote & vbCrLf & "Added by Access"

On Error Resume Next
Set myOlApp = GetObject(, "Outlook.Application")
On Error GoTo CheckError
If myOlApp Is Nothing Then
Set myOlApp = CreateObject _
("Outlook.Application")
boolCreate = True
End If
Set myNameSpace = _
myOlApp.GetNamespace("MAPI")
Set myFolder = _
myNameSpace.GetDefaultFolder(13)
Set myItem = myOlApp.CreateItem(3)

With myItem
.StartDate = dateStDt
.Subject = sSub
.Body = snote
.Categories = "MyCategory"
.ReminderSet = False
.Save
End With

AddOLTask = True
Finish:
If Not myNameSpace Is Nothing Then _
Set myNameSpace = Nothing
If Not myFolder Is Nothing Then _
Set myFolder = Nothing
If Not myOlApp Is Nothing Then
If boolCreate Then
myOlApp.Quit
Set myOlApp = Nothing
End If
End If

Exit Function
CheckError:
AddOLTask = False
Select Case Err.Number
Case -2147352571
MsgBox "Date Error"
Case Else
MsgBox "Bad error" & Err.Number & " " _
& Err.Description
End Select
Resume Finish
End Function

Private Sub Command0_Click()
If AddOLTask("note", _
"A new task from Outlook", _
"4/1/01") Then
MsgBox "successful", _
vbOKOnly + vbInformation, _
"Outlook Task Addition"
Else
MsgBox "failed", _
vbOKOnly + vbCritical, _
"Outlook Task Addition"
End If
End Sub

by p7ants

One last detail. To use this code you will need to reference the "Microsoft Outlook 9.0 Reference Library" or what ever version you'll be using. Phil

This discussion is closed to new replies.