2 Questions about Class Modules and Datediff

M

Macrofinder

Class Module:
I am currently using Project 2000. I have written 2 separate class modules.
One event happens upon Project_BeforeClose and the other occurs on
Project_Open. I am unable to make both events work together. Can I have 2
separate application events work in my Global Project.mpt? Please advise.

DateDiff:
I have one of my duration fields set up as a custom ProjDatediff field.
Everything is working well, however it is calculating down to the
hour/minute. I would like it to calculate to the day (i.e. Finish4 =
12/12/05 8am and Finish = 12/12/05 4pm, calendar = standard, then Duration1 =
0d). Is this possible in a custom DateDiff field? If not, how do I
calculate a duration field to show the Datediff to the day??

Thank you so much. Happy New Year.
 
R

Rod Gill

Project open and Close events usually go in the ThisProject file of the
Global .mpt or project file: no need for a class module.

Try surrounding your formula with the ABS() function. This should remove the
fraction part of the date difference, hence the time part.
 
M

Macrofinder

What commands would I use to initiate the macro? Would I use a Sub
Project_Beforeclose and Sub Project_Open? I've crashed project once by
trying this, so I'm trying to avoid that this go around.
 
R

Rod Gill

In the ThisProject file use:


Private Sub Project_BeforeClose(ByVal pj As Project)

End Sub

Private Sub Project_Open(ByVal pj As Project)

End Sub
 
M

Macrofinder

The Proj_BeforeClose Event has always worked for me. I am still having
problems w/ the Proj_Open event. The event works fine as a macro, but when I
try to apply it to Proj_Open, nothing happens. Please see code below. In
addition to the code below, how would I have a message box pop up if the Cost
2 field does not equal 0. This is not working for me either.

Private Sub Project_Open(ByVal pj As Project)

For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
If t.Start <> t.Date1 Then t.Cost2 = 1
MSGBX = "Dates have been changed"
If t.Finish <> t.Date4 Then t.Cost2 = 2
MSGBX = "Dates have been changed"
End If
Next t

End Sub
 
R

Rod Gill

Add the line:
Dim T as Task

This may help. Code will run more reliably and faster if you always declare
your variables.
 
M

Macrofinder

Hi Rod...

I appreciate the suggestion, however the code still does not run. Here's
what I need the code to do.
I have many schedules linked to my schedule. The tasks in other schedules
drive my schedule and change my delivery dates. So, I would like to know
when a change occurs. I have limited fields to work w/ so I chose the ones
below. When I close the file I have the start/finish fields copy to
Date1/Date4 then save. Upon Open, if the Start date is different than Date1,
cost2=1 and if Finish is different than Date4, cost2=2. Upon open I would
like a message box to notify me if the cost2 field has a 1 or a 2.

Does this make sense? When I run my code as a macro, it works. When I run
it as a Project_Open event, it does not work. The message box has never
worked. Can you please direct me as to how to make this work properly?
 
R

Rod Gill

Hi,

Can't help further, but why not use a simpler system? When you close the
project, save to Baseline10. Create a New Tracking Gantt Chart that shows
Baseline10 instead of Baseline and then it's easy to see any change and
appreciate whether that change is critical or not.

Another way is to make sure that all critical delivery dates are duplicated
at the top of the schedule. That way when you open the schedule you can see
if any have moved, especially if you have a deadline date for when they need
to be delivered.
 
M

Macrofinder

That is a great idea, however my field selection is limited.
As far as you know, I should be able to run my Project_Open, as is and my
Project_BeforeClose w/ no issues.
 
R

Rod Gill

Can't help you. Project_Open works fine for me. Have you tried a lower macro
security level?
 

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