DateDifference Help

J

Joe Martocci

How can I do this for a task that uses a different caldendar than the
Project's default calendar? I've tried messing around using the Project
help, but I keep getting errors with whatever I try. Here's what I've tried
so far:

t_datediff = Application.DateDifference(t_task.Start,
ActiveProject.StatusDate, t_task.Calendar)
t_datediff = Application.DateDifference(t_task.Start,
ActiveProject.StatusDate, 21)
t_datediff = Application.DateDifference(t_task.Start,
ActiveProject.StatusDate, BaseCalendars(t_task.Calendar))
 
J

Jack Dahlgren

Hmmm... t.Calendar returns a string with the calendar name, but
Application.DateDifference expects a calendar object.
I just don't see any way to get from one to the other.
The only real workaround might be to create a calendar for the task like this:


Sub findTaskCalendar()
Dim t As Task
Set t = ActiveProject.Tasks(3)
Dim c As Calendar
BaseCalendarCreate Name:="tempI", fromname:=t.Calendar
oldcal = t.Calendar
'c = t.Calendar.Item(1)
Find "id", "equals", t.ID
'Find , t.ID
't.SetField taskfield:=pjTaskCalendar, Value:="tempC"
MsgBox t.Calendar
SetTaskField field:="Task Calendar", Value:="tempI", AllSelectedTasks:=True
MsgBox Application.DateDifference(t.Start, t.Finish, tempI)
SetTaskField field:="Task Calendar", Value:=oldcal, AllSelectedTasks:=True
End Sub

but that has the problem of creating a bunch of different calendars and I
don't know of anyway to delete them when you are done with them... at least
in project 2000. Maybe a later version solves this...

Sorry to not give a good answer. Looks like a hole in the object model to me.

-Jack Dahlgren
 
J

Joe Martocci

Jack,
Thanks for the feedback, I did a little more research and came up with a
solution.

t_datediff = Application.DateDifference(t_task.Start,
ActiveProject.StatusDate, ActiveProject.BaseCalendars(t_cal))

I set the t_cal variable to the current task Calendar earlier in the For
Loop using an If statement that if the Task Calendar is set to "None" the
t_cal variable = the Project Base Calendar otherwise it's set to the Task
Calendar. Seems to work on the test scenario I created that was identified
the problem in the first case.

Time will tell.
 
J

JackD

Joe,

Care to post the entire code? It would be nice to have it here for
reference.

-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