Automating Outlook Task (1 Viewer)

Just1

Registered User.
Local time
Today, 07:29
Joined
Jan 9, 2005
Messages
50
I am building a basic client database which contains a "date last contacted" field and "date of next contact", where the date of next contact is run by formula to be 2 months after the date last contacted. I want a message to appear on the appropriate date on the Outlook Task list to say "contact ..(name),...(company),...(tel no).

I am fairly new to Access and a complete stranger to programming, although I have tried to get my head around some of the VBA code. I have been on the microsoft.com website but to be honest, it's just too technical. Is anyone able to help someone as new to this as me????!!!!!!

Your help appreciated. :eek:
Just1
 

PC User

Registered User.
Local time
Today, 07:29
Joined
Jul 28, 2002
Messages
193
I'm working on a project tracking database for my manager and I've programmed it for sending out e-mail notifications, but after seeing this discussion, I'm wondering if Access can create tasks on other user's Outlook. It's possible to do that directly through Outlook, but I'd like to have that coordinated with the project information in our project database.

Does anyone know how to use automation to add a task or a reminder to another user's outlook on a company's network? This is a little different from the original quesion in this discussion.

Thanks,
PC
 

Travis

Registered User.
Local time
Today, 07:29
Joined
Dec 17, 1999
Messages
1,332
You can Automate a Task Request. This does not directly create a task, but sends an email to a person letting them know that a task has been requested. They get to accept/decline the request.

Most of the Code is the same, just use Outlook.TaskRequestItem instead of Outlook.TaskRequest
 

PC User

Registered User.
Local time
Today, 07:29
Joined
Jul 28, 2002
Messages
193
I found this example in Outlook's VB editor's help on task assignments.
Example
This Visual Basic for Applications (VBA) example uses CreateItem to create a simple task and delegate it as a task request to another user. To run this example, replace 'Dan Wilson' with a valid recipient name.
Code:

Sub AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipient
Set MyItem = myOlApp.CreateItem(olTaskItem)
MyItem.Assign
Set myDelegate = MyItem.Recipients.Add("Dan Wilson")
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Prepare Agenda For Meeting"
myItem.DueDate = Now + 30
myItem.Display
myItem.Send
End If
End Sub


And I'm trying to adapt it to my application, but it gives me an error that its trying to write an attachment to a folder other that an Outlook folder. What does that mean? Do I need to designate a temporary location for the attacment file? See my code below. Can someone help me with this?
Code:

Public Function AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipient
Dim strReciprient As String, strResponsibleParty As String 'These are the same person
Dim strProject As String 'ActionDescription
Dim strFacility As String
Dim strFrequency As String
Dim strDueDate As String
Dim frm As Form
Dim sfN As Form 'Program Notification SubForm

Set frm = Forms!frmMainEntry.Form
Set sfN = frm.[fctlNotifications].Form
If sfN.[ProgramID] = sfN.[txtID] Then

strProject = sfN.ProgramDescription
strFacility = sfN.Facility
strDueDate = sfN.DueDate
strFrequency = sfN.FrequencyOfService
strReciprient = sfN.EmailAddress
strResponsibleParty = sfN.ResponsibleParty
strSender = frm!txtWelcome
Else
Exit Function
End If

Set myItem = myOlApp.CreateItem(olTaskItem)
myItem.Assign
Set myDelegate = myItem.Recipients.Add(strReciprient)
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Notification Of Compliance Requirement"
myItem.Body = vbCrLf & vbCrLf & vbCrLf & _
"To: " & strResponsibleParty & vbCrLf & vbCrLf & vbCrLf & _
"This is to notify you that the requirement for " & strProject & " at the " & _
strFacility & " is due on " & strDueDate & "." & vbCrLf & _
strProject & " is required " & strFrequency & "." & vbCrLf & vbCrLf & vbCrLf & _
"Keep On Track With Safety" & vbCrLf & strSender
myItem.DueDate = strDueDate
myItem.ReminderTime = DateAdd("ww", -1, strDueDate) 'Remind 1 Week before Due Date.
'myItem.Display
myItem.Send
End If
End Function
 

PC User

Registered User.
Local time
Today, 07:29
Joined
Jul 28, 2002
Messages
193
Thanks for your reply Travis,

I'm trying to apply your recommendation to the code that your suggested and I have a few questions. If I understand your suggestion correctly, I changed the following lines:
From:
Dim OutlookTask As Outlook.TaskItem
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)

Changed To:
Dim OutlookTask As Outlook.TaskRequestItem
Set OutlookTask = OutlookApp.CreateItem(olTaskRequestItem)

Somehow I now get a syntex error and I think its at the line:
Set OutlookTask = OutlookApp.CreateItem(olTaskRequestItem)

My entire code is now:
==================================
Function fncAddOutlookTask()
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskRequestItem
'Information from subform
Dim strReciprient As String, strResponsibleParty As String 'These are the same person
Dim strProject As String 'ActionDescription
Dim strFacility As String
Dim strFrequency As String
Dim strDueDate As String
Dim frm As Form
Dim sfN As Form 'Program Notification SubForm

Set frm = Forms!frmMainEntry.Form
Set sfN = frm.[fctlNotifications].Form
If sfN.[ProgramID] = sfN.[txtID] Then

strProject = sfN.ProgramDescription
strFacility = sfN.Facility
strDueDate = sfN.DueDate
strFrequency = sfN.FrequencyOfService
strReciprient = sfN.EmailAddress
strResponsibleParty = sfN.ResponsibleParty
strSender = frm!txtWelcome
Else
Exit Function
End If

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookTask = OutlookApp.CreateItem(olTaskRequestItem)

With OutlookTask
.Subject = "Notification Of Compliance Requirement"
.Body = vbCrLf & vbCrLf & vbCrLf & _
"To: " & strResponsibleParty & vbCrLf & vbCrLf & vbCrLf & _
"This is to notify you that the requirement for " & strProject & " at the " & _
strFacility & " is due on " & strDueDate & "." & vbCrLf & _
strProject & " is required " & strFrequency & "." & vbCrLf & vbCrLf & vbCrLf & _
"Keep On Track With Safety" & vbCrLf & strSender
.ReminderSet = True
.ReminderTime = DateAdd("ww", -1, strDueDate) 'Remind 1 Week before Due Date.
.DueDate = strDueDate
'.ReminderPlaySound = True
'.ReminderSoundFile = "C:\Windows\Media\Ding.wav" 'Modify path.
.Save
End With
End Function
==================================
I hope you can help me with this.

Thanks,
PC
 

PC User

Registered User.
Local time
Today, 07:29
Joined
Jul 28, 2002
Messages
193
Thanks Travis,

I'll adapt my code to your KB reference next Monday and let you know what happened. I'm away from the office today.

PC
 

PC User

Registered User.
Local time
Today, 07:29
Joined
Jul 28, 2002
Messages
193
Thanks again Travis, your recommendations worked. For others to see, I'm including the working code below. Tasks are not like e-mails, in that I don't see a way to send a BCC to my managers. Unless someone else has any ideas about that, this code is still correctly programmed.
===============================================
Public Function AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.TaskItem
Dim myDelegate As Outlook.Recipient
'Information from subform
Dim strSender As String
Dim strReciprient As String, strResponsibleParty As String 'These are the same person
Dim strProject As String 'ActionDescription
Dim strFacility As String
Dim strFrequency As String
Dim strDueDate As String
Dim frm As Form
Dim sfN As Form 'Program Notification SubForm

Set frm = Forms!frmMainEntry.Form
Set sfN = frm.[fctlNotifications].Form
If sfN.[ProgramID] = sfN.[txtID] Then

strProject = sfN.ProgramDescription
strFacility = sfN.Facility
strDueDate = sfN.DueDate
strFrequency = sfN.FrequencyOfService
strReciprient = sfN.EmailAddress
strResponsibleParty = sfN.ResponsibleParty
strSender = frm!txtWelcome
Else
Exit Function
End If

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)

myItem.Assign
Set myDelegate = myItem.Recipients.Add(strReciprient)
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Notification Of Compliance Requirement"
myItem.Body = vbCrLf & vbCrLf & vbCrLf & _
"To: " & strResponsibleParty & vbCrLf & vbCrLf & vbCrLf & _
"This is to notify you that the requirement for " & strProject & " at the " & _
strFacility & " is due on " & strDueDate & "." & vbCrLf & _
strProject & " is required " & strFrequency & "." & vbCrLf & vbCrLf & vbCrLf & _
"Keep On Track With Safety" & vbCrLf & strSender
myItem.DueDate = strDueDate
myItem.ReminderTime = DateAdd("ww", 1, strDueDate) 'Remind 1 Week before Due Date.
'myItem.Display
myItem.Send
End If
End Function
===============================================

Thanks,
PC
 
Last edited:

Users who are viewing this thread

Top Bottom