Date Range bug in VB?

G

Geoff Schwab

Greetings,

I am a newby to Project VB but I have a development background. I have
written some macros that take my projects and filter them by resource and
milestone (filter out tasks not assigned to the resource and are not a
milestone), then spit out gif images based on date ranges for our
milestones.

This works well except that the gifs show all tasks (I select all tasks)
rather than the tasks that are relevant to the date range of the milestone.
I would like to somehow either only select the tasks within that date range
or apply a second filter (as far as I can tell only one filter works at a
time) that would specifiy the date range to be printed.

I tried a "hack" where I created a filter for each resource that would
filter tasks that are not assigned to that resource and not in a specified
date range. For some reason, Project only displayed the resource's first
task so I tried an even simple example:

FilterApply name:="Date &Range...", Value1:="5/14/04", Value2:="6/17/04"

This still filters everything but each resource's first task in that range.
Of course, when you apply the filter from Project's Project->Filter For menu
it works fine. Looks like a bug to me!

Any ideas or better ways to accomplish this?

Basically what I want to do is:
1. Filter all tasks that are not either assigned to a specific resource or a
milestone (works fine)
2. And filter all tasks not in a specified date range or select all tasks
within the range (cannot get it to work)
3. Print a gif of the selected tasks (works fine)

My basic code loop looks like:

' Loop for each resource
For I = 0 To 3

' Loop for each milestone date range
For j = 0 To 16

Dim saveName As String
saveName = "C:\blah\" + Names(I) + "_M" + Format(j + 1) + ".gif"

If fs.FileExists(saveName) Then
fs.DeleteFile filespec:=saveName, force:=True
End If

' My custom filter
FilterApply name:="Milestones and Resource", Highlight:=False,
Value1:=Names(I)
Sort Key1:="Finish", Outline:=False

' This is what I need to fix (should only select tasks in the
date range)
SelectTaskColumn Column:="Name"
EditCopyPicture Object:=False, ForPrinter:=2, SelectedRows:=1,
FromDate:=dates(j * 2), ToDate:=dates(j * 2 + 1), fileName:=saveName,
ScaleOption:=pjCopyPictureShowOptions

Next
Next

Thanks,
Geoff
 
R

Rod Gill

Hi,

The answer is one filter that filters for your resource and the date range
in one go.
Record a macro of creating a filter for a resource and a specific date
range.
Edit the recorded macro so the resource name and dates are passed as
parameters in your code (rather than use the specific ones you entered as
values when recording the create filter).

For looping thru all resources, easier code is:

Dim R as Resource

For Each R in ActiveProject.Resources

Next R

--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.projectlearning.com/
 
G

Geoff Schwab

Hi Rod,

Thanks for the reply and sorry if I am in the wrong NG, but I guess I don't
understand what x.vba is for if not VB questions.

Anyway, I actually did try your solution at first but the date range does
not work in VB which is my whole problem. When I run the code to apply the
standard date range filter it doesn't even work. It filters everything but
the first task in the range. It works fine when I run it from the menu
though.

That repro code is simplying using Project's standard filter:
FilterApply name:="Date &Range...", Value1:="5/14/04", Value2:="6/17/04"

Geoff
 
J

John Beamish

This .vba newsgroup is a vestigial remnant. The .developer newsgroup is the
correct newsgroup for VBA questions.
 
J

JackD

Geoff,

Have you tried turning on the macro recorder and constructed the filter from
scratch (not just selecting and applying the filter)?
Can you post the code that is not working? It is really hard to debug if we
can't read your code.

-Jack
 
G

Geoff Schwab

Hi All,

Thanks for your help, I was able to get it working by recording the creation
of the filter (I had no idea you could do that).

I still don't know why calling the pre-created and default date range
filters from code didn't work, but this does:

FilterEdit Name:="My Date Range", TaskFilter:=True, Create:=True,
OverwriteExisting:=True, FieldName:="Finish", Test:="is greater than or
equal to", Value:=dates(I * 2), ShowInMenu:=False, ShowSummaryTasks:=False

FilterEdit Name:="Date Range", TaskFilter:=True, FieldName:="",
NewFieldName:="Start", Test:="is less than or equal to", Value:=dates(I * 2
+ 1), Operation:="And", ShowSummaryTasks:=False

FilterApply Name:="Resource and Date Range"

Thanks again,
Geoff
 

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