FilterEdit and FilterApply only work once

E

exuviae

I am trying to locate task by a text field in project when updating it from a
database. My problem is the filter only works the first time, after that
ActiveSelection.Task will equal null, even if i am applying the same filter
twice. I am using c# and my code looks like this :

if (firstEver)
{
msProjectApp.FilterEdit("TaskOIFilter", true, true, true,
Missing.Value, Missing.Value, "Text19", Missing.Value, "equals", TaskOI,
Missing.Value,false,true);
firstEver = false;
}
else
{
msProjectApp.FilterEdit("TaskOIFilter", true, false,
true,true, Missing.Value, Missing.Value,"Text19","equals", TaskOI,
Missing.Value, false, true);
}
msProjectApp.FilterApply("All Tasks", false, Missing.Value,
Missing.Value);
msProjectApp.SelectAll();
msProjectApp.FilterApply("TaskOIFilter", false, Missing.Value,
Missing.Value);
msProjectApp.SelectAll();

foreach (MSProject.Task task in msProjectApp.ActiveSelection.Tasks)
{
// first time this works, next time through
msProjectApp.ActiveSelection.Tasks=null
}
 
R

Rod Gill

You need to upgrade to Visual Studio 2010 the second it's released. Optional
and named parameters (finally available in 2010) will make your code
readable. If you can't upgrade, use VB so named and optional parameters
makes Office code easy and quick to read and maintain!

In your loop of tasks, do you have a blank task or two in project? You need
to test for Nothing. In VBA:

For Each Tsk in ActiveProject.Tasks
if not Tsk is Nothing then
'Code
End If
Next Tsk

The next thing is that msProjectApp.ActiveSelection.Tasks=null doesn't make
sense. You can't nullify all selected Tasks. You can delete them, but not
set them to Null or even Nothing. The collection Tasks does not have a
default property or method.

--

Rod Gill
Microsoft MVP for Project - http://www.project-systems.co.nz

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




exuviae said:
I am trying to locate task by a text field in project when updating it
from a
database. My problem is the filter only works the first time, after that
ActiveSelection.Task will equal null, even if i am applying the same
filter
twice. I am using c# and my code looks like this :

if (firstEver)
{
msProjectApp.FilterEdit("TaskOIFilter", true, true, true,
Missing.Value, Missing.Value, "Text19", Missing.Value, "equals", TaskOI,
Missing.Value,false,true);
firstEver = false;
}
else
{
msProjectApp.FilterEdit("TaskOIFilter", true, false,
true,true, Missing.Value, Missing.Value,"Text19","equals", TaskOI,
Missing.Value, false, true);
}
msProjectApp.FilterApply("All Tasks", false, Missing.Value,
Missing.Value);
msProjectApp.SelectAll();
msProjectApp.FilterApply("TaskOIFilter", false, Missing.Value,
Missing.Value);
msProjectApp.SelectAll();

foreach (MSProject.Task task in msProjectApp.ActiveSelection.Tasks)
{
// first time this works, next time through
msProjectApp.ActiveSelection.Tasks=null
}

__________ Information from ESET Smart Security, version of virus
signature database 4937 (20100311) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4937 (20100311) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 

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