MS Project 2000 OLE Blank Line

P

project-guy

I have an application which accesses MS project 2000 using OLE, via the
MsPrj9.olb type library. When you use the Insert-Task menu selection in MS
Project, MS project enters a new Task ID and a unique Task ID. None of the
other fields in Project are updated.

When I try to read a Blank line from my application, an exception is
generated. I am able to read all properties defined in the MSPrj9.olb type
library. Is there a property available which I can query or test to see if a
task is a blank line (spacer) or a real task?
 
J

JackD

In VBA I usually use

For each Task in ActiveProject.Tasks
if not Task is Nothing then
'do stuff
end if
Next Task
 
D

Dan Roy

You have a VBA example from within project. I am using Borland's Delphi via
the MSPrj9.olb Type Library. What fields within Project 2000 become populated
as a task evolved from a new task, i.e you have executed the menu choice of
"Insert New Task" to that task becoming a real task with populated fields.
When you look at the database export of an MS project file ( an mpd file using
MS Access), the only fields which are populated in the MSP_Task table are the
ID, UID, and several property fields. The normal tasks defaults are not
loaded nor does the task possess any duration or date information. It is only
when you click on the task line that the newly inserted task become a real
task.

How can I differentiate between the two conditions? I am already
conditioning my read of the file to first check the Task.Names field for
length >0. Since these are OLEVariant fields, this should work but I am still
getting exceptions. Do you have any suggestions?
Thanks

Project-guy
 
J

JackD

I'm not a Delphi user, so I can't comment on what you need to do there, but
the tasks.add method allows specifying the name of the task. I suggest that
you take advantage of this and give it a name when you create it.

I would expect that you would use this method instead of choosing from a
menu, but then again, I know nothing about Delphi.

--------tasks.add syntax-------

expression.Add(Name, Before)

expression Required. An expression that returns a Resources or Tasks
collection.

Name Optional String. The name of the new resource or task. The default
value is Empty.

Before Optional Long. The position of the task or resource in its
containing collection. The default value is the position of the last item in
the collection.
 
D

Dan Roy

Thanks for trying to help. Perhaps if I explain my problem differently. Forget
that I am using delphi. If you Open MS Project, select "Insert new task" from
the menu and then save the project. Do not click on the task before you save.

You will see that you have a blank line in the Project File that has an ID and
UID defined, but no duration or dates. I bet if you try to read this blank line
using VBA you will have an error. If you would be willing to try this I believe
you will understand my problem.

Dan
 
E

Earl Lewis

Dan,

Can you just trap the error number? In the MSProject VBE it throws err.number = 91, err.description = "Object variable or With block not defined". Not sure if that will help you or not. I would think that the errors are exposed through the type library. I just don't use it enough to know for sure.

Earl
You have a VBA example from within project. I am using Borland's Delphi via
the MSPrj9.olb Type Library. What fields within Project 2000 become populated
as a task evolved from a new task, i.e you have executed the menu choice of
"Insert New Task" to that task becoming a real task with populated fields.
When you look at the database export of an MS project file ( an mpd file using
MS Access), the only fields which are populated in the MSP_Task table are the
ID, UID, and several property fields. The normal tasks defaults are not
loaded nor does the task possess any duration or date information. It is only
when you click on the task line that the newly inserted task become a real
task.

How can I differentiate between the two conditions? I am already
conditioning my read of the file to first check the Task.Names field for
length >0. Since these are OLEVariant fields, this should work but I am still
getting exceptions. Do you have any suggestions?
Thanks

Project-guy
 
J

JackD

I completely understand your problem. The problem of blank lines in project
files is well known and the solutions are widely known.

The problem is that you appear to be doing something in a way which causes a
problem. I suggest that you do it in a different way and avoid the problem.
There are two alternate ways to avoid this problem. 1) detect the condition
and avoid it, 2) avoid creating the problem in the first place, and if you
can't avoid it, then simply handle the error.

1) In the case you describe, you would read it in VBA using the code I
posted. It works perfectly.
To refresh your memory the key statement is:

"if not Task is Nothing then"

2) Now, if I want to avoid having to use the statement above, and still want
to avoid having blank lines in project I would not use any method of
creating blank task lines. To do this simply use the Tasks.add method and
SPECIFY a name for the task. Then you will not have this problem.

As for error handling, in VBA you could use on error resume next. or
something similar. Obviously you need to determine what you want to do when
an error occurs.
 

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