Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Usage of Todays Date in filters??

Status
Not open for further replies.

Hesaf

IS-IT--Management
Aug 12, 2008
15
0
0
EU
I want to use the todays date in a filter.
How can I do that?
Apparently there is no field in the filter function that can be used as todays date without translating it to the date of today. That means that tomorrow the yesterdays date is set in the filter. The objective is to run the filter always with todays date.......
An example is valued!
 
Start Project and open YourProject
Alt+F11 (to open VBA)
In the left hand window look for "VBAProject(YourProject)"
Beneath that look for "Microsoft Project Objects". Expand that.
Look for "ThisProject (YourProject.mpp)"
Double-click on that line.
In the right hand box paste this code:

Private Sub Project_Open(ByVal pj As Project)
PDQBach
End Sub

In the left hand box look for "Modules"
If you don't see it then click on Insert > Module.

DoubleClick on "Modules"
DoubleClick on any module name
Paste the following code. This filters for Start dates greater than today -- modify as necessary to meet your requirements.



Sub PDQBach()
FilterEdit Name:="PDQBachTodayFilter", _
TaskFilter:=True, Create:=True, OverwriteExisting:=True, _
FieldName:="Start", Test:="is greater than", Value:=Now(), _
ShowInMenu:=True
End Sub
 
Thanks PDQBach.
This looks like the solution.
A macro for that specific filter works fine. The only issue I have is that the macro needs to be initiated once before you can use the filter.

Is there an automatic macro execution within MSP2007 at start up time without pressing any keys? That would add this filter immediately in the filter list without any actions.
The reason I ask this is that we want to provide ready filters to our users without initiation actions...
 
The code I provided works in 2003 the way you have requested: the filter is initialized and is ready to go when the file has been loaded.

If you want the filter applied as soon as the file is loaded then put this as the last line in the sub PDQBach.

FilterApply Name:="PDQBachTodayFilter
 
Yes the filter is working properly and it's visible when the macro is activated manually.
However, I want to have this filter loaded at MS Project start-up time without activating a macro manually. So automatic execution of this macro so that the filter is available for use.

The issue is that I want to have a todays date that is translated as the date of today and not translated to a date and then the date is fixed for future use.

Remark:
Without the filter apply name it is also visible in the filter list of 2007 when the macro is executed manually.
 
I've just tried it again ...

Once you put both pieces of code in the locations where I told you to put them, it works.

It goes without saying (but I'll say it anyway) you do have to save the project file and exit Project. From then on, whenever you open the project file the filter will be available.
 
PDQBach, thanks for the advice and your patience but I think I'm still doing something wrong or I don't understand.

Yes the filter is available after saving MSP and I did put the 2 pieces of programming in the proper place.

However, when I change the date of the computer to see if the now works fine, and I start MSP again and apply the filter from the list, somehow the date in the filter is still the previous date and not updated with the now (fake) date...

The filter is visible in the organiser...
When I delete the filter and close MSP and start it again, the filter is not created........

When pressing the macro button it works fine and when I change the date and press the macro button again it also works fine. So the issue I still have is that the start up of the schedule does not change the date in the filter to the now date but it's only refreshed after a manual activation of the macro.

I guess the issue is with the lines:
Private Sub Project_Open(ByVal pj As Project)
PDQBach
End Sub

This code should force MSP to start the macro automatically at the moment the plan is loaded in MSP? Right?
 
Are you running your tests in Virtual PC or one of the various Virtual Machine sw products?
 
No, standalone MSP2007 on laptop.
 
My MSP2007 is installed in a virtual box; when I changed the date in the virtual box the virtual box reset it within seconds back to the computer's date. When I did this in the virtual box I could actually watch it happen:

Start > Control Panel > Date and Time
set a new date and click on Apply

I watched the date in the calendar display and it would reset to today's date.

I tried the code in P2003 in my own computer (and on two other machines). It works correctly and can be demonstrated to work correctly using your process of resetting the computer date (and not, just to be specific, of course in the virtual machine but in the "main computer").

Boot computer
Load Project
Open projectfile
Looking at the filter, it shows today's date.
Exit from Project
Start > Control Panel > Date and time
Change the date to next Monday; click Apply
Load Project
Open projectfile
Looking at the filter it shows Monday's date.

The code I gave you works just fine. The issue now seems to be with your computer's date/time settings and what happens when you change the date/time.

 
What happens when you open the file on another machine?
 
Well, after some checks on other laptops it seemed that my macro security setting was too high which prevented the macro execution.......

Thanks!

Topic can be closed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top