Variables in Filters

P

pratta

I am attempting to create a filter for viewing tasks or sub projects
finishing or ongoing between 2 dates - eg, Month Start Date(MSD) and Month
End Date(MED).
The problem is that I ask for the MSD and the MFD to be entered, but then
for the next condition, require the MSD to be rekeyed. Is there a method for
saving the keyed variable in a filter?
 
G

Gerard Ducouret

Hello Pratta,
Only a VBA procedure can do that. Are you familiar with VBA ?

Gérard Ducouret
 
J

John

pratta,
I started out playing with filters but quickly decided that although
there might be some clever filter that will work, a VBA approach is much
easier. The following code should do what you need.

Sub ThisMonthStatus()
OutlineShowTasks expandinsertedprojects:=True
MonDates = InputBox("Enter Month Start Date and Month Finish Date " &
Chr(13) & _
"separated by a comma (e.g. MM/DD/YY,MM/DD/YY)")
MSD = CDate(Mid(MonDates, 1, InStr(1, MonDates, ",") - 1))
MFD = CDate(Mid(MonDates, InStr(1, MonDates, ",") + 1))
For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
t.Flag1 = False
If t.Summary = False Then
If t.Start >= MSD And t.Finish <= MFD And _
t.PercentComplete > 0 And _
t.PercentComplete <= 100 Then t.Flag1 = True
If t.Finish >= MSD And t.Start <= MFD And _
t.PercentComplete > 0 And _
t.PercentComplete <= 100 Then t.Flag1 = True
If t.Start <= MFD And t.Finish >= MSD And _
t.PercentComplete > 0 And _
t.PercentComplete <= 100 Then t.Flag1 = True
End If
End If
Next t
FilterEdit Name:="MS", taskfilter:=True, create:=True,
overwriteexisting:=True, _
FieldName:="flag1", test:="equals", Value:="yes", showinmenu:=False,
_
showsummarytasks:=False
FilterApply Name:="MS"
End Sub

John
Project MVP
 
P

pratta

Many Thanks John,
I am trying to run the pgm but am getting a Compile Error - Syntax Error on
the Mondates line.
Any further help appreciated.

Regards...........pratta
 
J

John

pratta,
I always test code before I post it, so I know this code runs. Since you
probably copied and pasted my code to your VBA editor and since the
"MonDates" line is the first line of code with a continuation character
sequence, I'm guessing the copy and paste didn't break the code properly
at the continuation break. In VBA the character sequence for a
continuation line is "space underscore" (i.e. " _"). If code lines are
broken without the continuation sequence, a syntax error will occur.

Check the code in your VBA editor and ensure the line breaks are valid.
If everything looks ok but you still get a syntax error, what part of
the line is being highlighted when it flags the error?

Hope this helps.
John
 

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