Applying a Date Filter with arguments from Visual Basic

J

Jon Fernandez

Hello,

I need to apply a date filter to my project via a Visual Basic macro. When I
apply it from the Menu Project->Filters->Date Interval and two date selection
dialogs appear, it works fine. It shows any tasks that starts, ends or lasts
during the given interval.
The problem is when I try to call FilterApply from my macro.

Sub FilterByPastCurrentNextMonth()
Dim a As Date
Dim b As Date
a = DateAdd("m", -1, Date)
b = DateAdd("m", 1, Date)

FilterApply Name:="z Date Interval", value1:=a, Value2:=b

End Sub

These two parametres don´t work well, because when I call this function, the
gantt chart only shows tasks that lasts or finishes during this interval, but
if it starts between Date "a" and Date "b", it does not appear.

The Project version I'm using is Project 2003 Professional (SP2).

What am I missing? Are the parameteres wrong?

Thanks in advance
 
R

Rod Gill

Hi,

Is this a filter you created yourself or the built in Date Range filter
renamed? Try recording a macro of you applying the filter manually. If the
filter is the built in one then I think it's part of an Add-in and not a
true filter at all. Record a macro of you creating a filter manually with
fixed dates in it. Then edit the recorded code to use your two dates.

In fact this is the sample macro I use in my book for demonstrating the
power of recording a macro and how a simple edit or two makes it more
useful.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
J

Jack Dahlgren

You have half the formula.
The date range needs to be modified with a couple of conditions.
First condition would be start is less than or equal to "b"
Second condition is that finish is greater than or equal to "a"
Use an "And" between them.
Turn on the macro recorder and build a new date range filter, then edit to
substitute your calculated dates.

-Jack
 

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