Updating Outlook Tasks??

Richard M

Registered User.
Local time
Today, 01:30
Joined
Sep 29, 2010
Messages
75
Hi everybody, Help

Using Access 2007 and new at working with Outlook

I created a form in Access to inport Outlook Tasks. Now I want to update the task in outlook. I created the code to import all the tasks into the form. Works great. Now I want to save the changes made back into Outlook Tasks. Borrowing code from the forum, I have changed it and put it into a module. All I am changing is the Task's body information.

The below code is to update a task in Outlook with the new information in the body. I am using the Subject to find the Task in Outlook. When code runs it skips over the updating process because the Select Case (taskType) has nothing in it even though it does in the step above it.

Can anybody tell me where I am going wrong?

Thanks Richard:(

Code:
Option Compare Database
Option Explicit
 
Function UpdateTask()
Dim objApp As Object
Dim objTaskItem As TaskItem
Dim objNS As NameSpace
Dim objTasks As MAPIFolder
Dim Subject As UserProperty
Dim RecordID As UserProperty
Dim taskID As UserProperty
Dim taskType As UserProperty
 
Dim TaskType1 As String
TaskType1 = "IMS_Task"
 
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objTasks = objNS.GetDefaultFolder(olFolderTasks)
 
Set objTaskItem = objTasks.Items.Find("[Subject]=" & Forms!frmshowalloutlooktasks!OLSubject) ' & " AND [TaskType1]='IMS_Task'")
 
Set taskType = objTaskItem.UserProperties.Find("objTaskItem") '(Forms!frmshowalloutlooktasks!OLSubject) [COLOR=green]'Here the taskType shows the subject[/COLOR]
 
Select Case (taskType) [COLOR=green]'shows nothing[/COLOR]
 
Case "taskType" 
 
If Not (Subject Is Nothing) Then 
 
If isnull(Forms!frmshowalloutlooktasks!DateCompleted)  Then 
 
objTaskItem.Body = Forms!frmshowalloutlooktasks!OLNotes
Else
objTaskItem.Body = Forms!frmshowalloutlooktasks!OLNotes
 
End If
End If
Case Else 
'do nothing
End Select
objTaskItem.Save
 
Done:
Set objApp = Nothing
 
Set objTaskItem = Nothing
Set objTasks = Nothing
 
Exit Function
 
Err_Handler:
MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
Resume Done
End Function
 
You could just create a link to the Access Task table. See here. Then you have full access and can treat the data as if it were just another Access table. Just be mindful how exposed this is though - you don't want the user deleting all their tasks.

hth
Chris
 
If I understand you correctly you want to find tasks. You find a task and set it to the object "objTaskItem". This object is declared as a taskitem. So you do not have to test that it is a task item. You will get an error if you try to set a mailitem to a taskitem object.

PS. If you are generating the tasks from your code as well. Then I would suggest you create your own userproperty and add your own uniqueID to that property. Then when it is time to search for the task you use this uniqueID - it means quicker finds and takes some of the guess work out of things.
 
You could just create a link to the Access Task table. See here. Then you have full access and can treat the data as if it were just another Access table. Just be mindful how exposed this is though - you don't want the user deleting all their tasks.

hth
Chris
Hmm, it seems that the linked table does not include the title! Not very helpful!
 
Hi darbid

If I understand you correctly you want to find tasks. You find a task and set it to the object "objTaskItem". This object is declared as a taskitem. So you do not have to test that it is a task item. You will get an error if you try to set a mailitem to a taskitem object.

PS. If you are generating the tasks from your code as well. Then I would suggest you create your own userproperty and add your own uniqueID to that property. Then when it is time to search for the task you use this uniqueID - it means quicker finds and takes some of the guess work out of things.

Thanks for the help. I striped the test out and the below code does work. I am using the sugject to find the task in Outlook. I still do not understand how the "create your own userproperty and add your own uniqueID to that property." works. Is this created in Outlook and how is it assigned?

Here is the code I used to update the task in Outlook.

Richard:D

Code:
Function UpdateTask()
Dim objApp As Object
Dim objTaskItem As TaskItem
Dim objNS As NameSpace
Dim objTasks As MAPIFolder
Dim Subject As UserProperty
Dim RecordID As UserProperty
Dim taskID As UserProperty
Dim taskType As UserProperty
Dim TaskType1 As String
TaskType1 = "IMS_Task"
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objTasks = objNS.GetDefaultFolder(olFolderTasks)
 
Set objTaskItem = objTasks.Items.Find("[Subject]=" & Forms!frmshowalloutlooktasks!OLSubject)
 
Set taskType = objTaskItem.UserProperties.Find("objTaskItem")
 
objTaskItem.Body = Forms!frmshowalloutlooktasks!OLNotes
 
 
objTaskItem.Save
Done:
Set objApp = Nothing
Set objTaskItem = Nothing
Set objTasks = Nothing
Exit Function
Err_Handler:
MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
Resume Done
End Function
 
If you are creating the task from access or you have a task as an object then you can add your own user properties.

eg
Code:
Task.UserProperties.Add "myProperty", olNumber, True
    Task.UserProperties.Item("myProperty").Value = myIDNumber
Where myUDNumber might be stored in a table in your database.

Then the next time you want to find the task you just use the find method on the myProperty and search with your myIDNumber from your table.

You are guaranteed to find it, unless it is deleted.
 
Thanks darbid,

I am off and running. But I will be back because I will be doing calendar next. I think I have learned enough to dig the hole deeper.

:)Richard
 
darbid,

You sent this to me, but I am confused. :confused: I see I can create one if I create a Task from Access, but I am not. I read the Outlook task that seems not to have an ID number to it. Here is the process I am using:

  1. I delete the current data in my tblTask table.
  2. Read Outlook Tasks and then put them into the tblTask table
  3. Update any information that I need to update
  4. Save it to Outlook Tasks
This process works, but does Outlook Task have an ID number That I can referrence to eliminate the Subject as being the key to update the Outlook Task?

Any idea on this?

Richard

If you are creating the task from access or you have a task as an object then you can add your own user properties.

eg
Code:
Task.UserProperties.Add "myProperty", olNumber, True Task.UserProperties.Item("myProperty").Value = myIDNumber
Where myUDNumber might be stored in a table in your database.

Then the next time you want to find the task you just use the find method on the myProperty and search with your myIDNumber from your table.

You are guaranteed to find it, unless it is deleted.
 
Most Outlook items have a unique ID it is a long string. When you get each item, you could also save this id in your table.

The problem is that Outlook changes these IDs. I do not know all the times that it does this, but it does it for example if you move an item from one folder to another. Thus you will never find it again.

Thus you will find many people advocating that you add your own property or use the mileage property.

So the process is.

Get your Outlook item as an object.
Get the properties you want
add a new record to your database
get the primary number of that record.
add it to a property of the Outlook item

Then loop to the next.
 
darbid,

Thus you will find many people advocating that you add your own property or use the mileage property.

So I take it that the person would have to add their own number in the mileage property? Is there any way to have Outlook auto put a number in the mileage property?

Richard
 
By the way darbid, what do people use for the calander ID?

If I create my own property, then I would have to assign it to Tasks in Outlook. Looked at create a New field in Outlook and there does not appear to have auto numbering.

any ideas?

Richard
 
Not that I know of.

I use the Mileage property if the Outlook item has it. Otherwise I make my own. Thus for tasks I make my own.
 

Users who are viewing this thread

Back
Top Bottom