Sorting tasks by calculated field - automatically update task-fiel

B

BMunk

Hi,
I have a calculated field in Tasks that I would like to sort the tasks by,
but Outlook does not allow that.
Is it posible to make another Integer field (that can be sorted), and have
an event fire whenever a task item is updated so that I can assign the
content of the calculated field into the new integer field?
(Or any other work-around to sort by calculated field?)

Thanks!
 
K

Ken Slovak - [MVP - Outlook]

If you want an event when the item is saved use the item.Write() method. If
you want it when a built-in property is changed use item.PropertyChange(),
for a user property being changed use item.CustomPropertyChange().
 
B

BMunk

Thanks a lot for the quick reply!

I have never programmed in Outlook before (Outlook 2007), so could you give
me a quick hint/reference to sample code for setting a custom task field
value to the value of another custom formula field when one of the custom
formula field of a task changes?

I would appriciate a lot - thanks!
 
K

Ken Slovak - [MVP - Outlook]

Where is this code running, is this form code or Outlook VBA macro code or a
COM addin or ...?

It sounds like form code, in which case your best bet is to go to
www.outlookcode.com and look there in the Forms information, especially in
the sections about bound controls and control and property syntax.
 
B

BMunk

I guess it should run in "ThisOutlookSession" - I don't have a special form.
It's basically just a custom field I add to the Tasks to create a column I
can use to sort my tasks. But the column I have added is made as a "formula"
field that Outlook won't use for sorting for some reason. It is however
possible to add another custom Integer field that Outlook can use for
sorting. So everytime a task is updated I want to copy the value of the
calculated field to this custom Integer field.

I did find some sample code in another thread that I think can be a starting
point:

Dim WithEvents myInspectors As Inspectors
Dim WithEvents myTaskItem As TaskItem
Private Sub Application_Startup()
Set myInspectors = Outlook.Inspectors ' Here I get a "Syntax error"!
End Sub
Private Sub myInspectors_NewInspector(ByVal Inspector As Inspector)
If TypeName(Inspector.CurrentItem) = "TaskItem" Then
Set myTaskItem = Inspector.CurrentItem
End If
End Sub
Private Sub myTaskItem_Close(Cancel As Boolean)
Set myTaskItem = Nothing
End Sub
Private Sub myTaskItem_PropertyChange(ByVal Name As String)
If Name = "Status" Then
If myTaskItem.Complete = True Then
MsgBox "Task " & myTaskItem.Subject & " now completed"
End If
End If
End Sub

.... And then change to content of the _ProportyChange Sub to copy the value.

BUT adding this in ThisOutlookSession gives me a "Syntax error" in the "Set"
line of the application_Startup() sub. I can replace it with a MsgBox that
works.
Actually all content within the "Sub's" are colored red.

It's Outlook 2007. I have no prior experience with VBA coding, so any help
will be appriciated.
 
B

BMunk

Update:
I solved the "syntax" error. For some reason copy/paste made some invisible
"syntax" error! If I rewrote the text, all can compile :)

However, none of the other Sub's (exept the Startup) is ever executed when I
change a task status to anything (e.g completed). I check this with a MsgBox
in the beginning of all the sub's.

Any suggestions?
 
B

BMunk

How can I get an event when any task in the task folder has any of it's
properties updated? (e.g. Status set to "Deferred")?
 
K

Ken Slovak - [MVP - Outlook]

You are attempting to set an Inspectors object collection to an interface.
That line should read:

Set myInspectors = Application.Inspectors
 
K

Ken Slovak - [MVP - Outlook]

To get an event when any item in the Items collection of the Tasks folder is
changed put this line at the top of the ThisOutlookSession class with the
other declarations:

Dim WithEvents colItems As Outlook.Items

Then in your Application_Startup() handler put this:

Set colItems = Application.Session.GetDefaultFolder(olFolderTasks).Items

That will let you handle the ItemChange event on that Items collection. You
will get a reference to the item being changed. It will not tell you what
property was changed.

For that you would have to instantiate a separate TaskItem declared
WithEvents for every member of the Selection collection when the
ActiveExplorer.CurrentFolder is the Tasks folder. You'd have to change those
instantiated items each time selection changed or the view moved to a
different folder.
 
B

BMunk

Thanks!

Ken Slovak - said:
To get an event when any item in the Items collection of the Tasks folder is
changed put this line at the top of the ThisOutlookSession class with the
other declarations:

Dim WithEvents colItems As Outlook.Items

Then in your Application_Startup() handler put this:

Set colItems = Application.Session.GetDefaultFolder(olFolderTasks).Items

That will let you handle the ItemChange event on that Items collection. You
will get a reference to the item being changed. It will not tell you what
property was changed.

For that you would have to instantiate a separate TaskItem declared
WithEvents for every member of the Selection collection when the
ActiveExplorer.CurrentFolder is the Tasks folder. You'd have to change those
instantiated items each time selection changed or the view moved to a
different folder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top