Direct access to task's field data (Name) or Lookup using UniqueID

B

bstobart

I want to be able to popup a Msgbox with a specific field value of a given
task whenever the user hits the save button. I want this to happen quickly
so that the user isn't irritated by the delay. How can I quickly and
directly reference a task's field data? One way is to use the task's ID (eg
Activeproject.Tasks(100).Start), but as soon as a new task is added aboe task
100 the task's ID changes. Is it possible to reference data about a task
using its UniqueID in the same way? Alternatively, does Project have
anything like the "Name" functionality in Excel?
 
B

bstobart

Rod,

Thanks. That's exactly what I needed. It looks ridiculously obvious at
this point, but I believe I was not aware of that format. I knew about
Activeproject.Tasks(100).Start

but I didn't realize the index (100) could be applied after a task's field
value, as you've done, ie

Activeproject.Tasks.UniqueID(100).Start

As far as my specific application, in case anyone out there is interested, I
now have a nice little display that pops up each time the user saves, using
the following two subroutines:

In the Project Module:

Private Sub Project_BeforeSave(ByVal pj As Project)
Call ShowKeyReleaseDates
End Sub

In a module called SpecialUtils:

Sub ShowKeyReleaseDates()
MsgBox Prompt:= _
"Project Start Date: " & Format(ActiveProject.ProjectStart,
"mmm dd, yyyy") & Chr(10) & Chr(10) & _
"Soft Code Freeze: " &
Format(ActiveProject.Tasks.UniqueID(6116).Finish, "mmm dd, yyyy") & Chr(10) &
Chr(10) & _
"Hard Code Freeze: " &
Format(ActiveProject.Tasks.UniqueID(6115).Finish, "mmm dd, yyyy") & Chr(10) &
Chr(10) & _
"Final Release Testing: " &
Format(ActiveProject.Tasks.UniqueID(2387).Finish, "mmm dd, yyyy") & Chr(10) &
Chr(10) & _
"Release Complete: " &
Format(ActiveProject.Tasks.UniqueID(6118).Finish, "mmm dd, yyyy") & Chr(10) &
Chr(10) & _
"Project End Date: " & Format(ActiveProject.ProjectFinish, "mmm
dd, yyyy") & Chr(10) & Chr(10), _
Title:="6.4 Key Release Dates"
End Sub

This of course assumes that the unique ids of these tasks don't change,
which is a fairly reasonable assumption in my case. Now that I think of it,
I'm going to add an "On Error Resume Next" command, just in case.

-Bill
 
R

Rod Gill

Hi,

The most likely way of Unique ID's changing is if Tasks are cut and pasted.
This does create new Tasks, hence new Unique IDs.

You can use Tasks("Task Name") provided the task has a guaranteed unique
name.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
J

Jack Dahlgren

I agree with Rod.
If you want the code to work across different projects using Name would also
be useful.
In that case you probably want the code to verify that there are not two
milestones with the same name and warn the user if there are.

-Jack Dahlgren
 
A

Aditya

Hi,

I am using C# and the ActiveProject.Tasks.UniqueId(index) property doesnot
exist for me? or does it? and I do now know how to use it?
The problem is that I am creating an Application object called application
and I using, Application.Activeproject.Tasks here, the library shows only a
get_UniqueID method and nothing else. I am not able to get to the
Application.Activeproject.Tasks.UniqueID at all...Please help!

Thanks in advance.
Aditya
 

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