Populate task field based on value of other field

J

jparker

Hi all,

I'd like to automatically populate a custom task field based on the value of
another field.

Specifically, I basically want this to happen when creating or modifying a
task:
if "Due Date" == None {
"Due Date Exists" = No;
}

So then I can sort based on this field.

Any suggestions on how to get started? How do I go about creating the code
to do this? I'm just looking for a kick in the right direction here.

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

Where is this code supposed to run, a COM addin or a custom form or ...?

A null Date value in Outlook is 1/1/4501, that's what you have to check for.

If "Due Date Exists" is a UserProperty you added then you access it as
follows, assuming "item" is the item in question:

item.UserProperties.Item("Due Date Exists") ' VBA code, syntax will vary
by language

To access the DueDate property would be item.DueDate.

Of course since all non-set date fields are 1/1/4501 you could just sort by
DueDate and those items would be either at the top or bottom of your
collection depending on if you sorted the collection in ascending or
descending order.
 
J

jparker

Hi Ken, thanks for the reply.

I'm trying to sort my Task list by due date, with No Date tasks at the
bottom (since they're unconstrained).

I've only been able to come up with the following options sorting by due date:

No date
Today
Tomorrow
....

or

....
Tomorrow
Today
No Date

I want this:
Today
Tomorrow
....
No Date

My solution was to add a user-defined field that's set to true if a due date
exists and false if it doesn't, and I could sort by that field first, then
due date second.

Is there a better way?

Thanks,
Joel
 
K

Ken Slovak - [MVP - Outlook]

Based on how you want items to sort you'd have to sort on your user property
value unless you first used a restricted Items collection, which probably
would be the better way.

What you do is get your Items collection and call the Restrict method on it,
filtering out any items that have DueDate = #1/1/4501#. The new Items
collection returned by the Restrict method would then contain no items
without a DueDate and could be sorted up or down as you chose.
 
J

jparker

Ken,

Sorry, I'm not very experienced with Outlook other than using it day-to-day.

How do I use this restricted Items collection you speak of, and would it
allow me to sort based on date while ignoring No Date entries, but still
display the No Date tasks at the bottom? Or would it hide them for good?

The gist of my original question is the same as the one in your response: I
don't know where my code would go or how it would need to get run. Do use my
custom field, I'm guessing I'd need to populate it when any task was created
or modified, but I have no info other than that.

Thanks,
Joel
 
K

Ken Slovak - [MVP - Outlook]

The restricted collection I was talking about would not have any items with
no due date.

Even with your user property I don't think you can end up sorting the way
you want. You'd have to see.
 
J

jparker

Going back to my original question, where would I put this code such that it
would populate my user field every time a task is created/modified?

Thanks,
Joel
 
K

Ken Slovak - [MVP - Outlook]

In the form select the Properties for your user field and go to the Value
tab. You can use the formula builder there to set up your condition. Set the
calculation to be automatic and set up the formula something like this:

IIf( [Due Date] = #1/1/4501# , [Due Date Exists] = No, [Due Date Exists] =
Yes )
 
J

jparker

I would have to design a custom Task form? There's no way to add my field
behind the scenes while using the existing Task form, or hook into it
somehow? Would this replace the default Task form? What would happen with
tasks created automatically through other apps (through COM)?

Thanks,
Joel


Ken Slovak - said:
In the form select the Properties for your user field and go to the Value
tab. You can use the formula builder there to set up your condition. Set the
calculation to be automatic and set up the formula something like this:

IIf( [Due Date] = #1/1/4501# , [Due Date Exists] = No, [Due Date Exists] =
Yes )




jparker said:
Going back to my original question, where would I put this code such that
it
would populate my user field every time a task is created/modified?

Thanks,
Joel
 
K

Ken Slovak - [MVP - Outlook]

If you want that you either need a custom form or you need to write code in
the Outlook VBA project to populate your UserProperty based on the DueDate.
In that case the formula would be different. You'd also have to manage not
only any task when it was opened but also when it is selected in a folder
view and modified using in-cell editing.

It's likely that custom task forms might not be compatible with other
applications.
 

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