VBA - Error 1004

P

Paul Conroy

I have placed the macro below in the before save event of the Ent.Global and
all works well.

That is except for in the following scenario, when the app returns a runtime
1004 error:
User makes a change in the schedule, select file, close, keeping the
settings of save changes and check-in project.

Any insight as to why this error only occurs in the scenario would be
greatly appreciated.

Thanks

Paul

'check that a project is loaded
If Not pj Is Nothing Then
'check whether the plan has been previsouly saved
If ActiveProject.LastSaveDate <> "" Then
'was any previous save less than 15 mins ago
If DateDiff("n", ActiveProject.LastSaveDate, Now) < 15 Then
'prompt user to save baseline
Dim msg As Integer
msg = MsgBox("Do you wish to save an interim baseline?",
vbYesNo, "Save Baseline")
'if response is yes then save baseline 10
If msg = vbYes Then
BaselineSave All:=True, Copy:=0, Into:=20
End If
End If
End If
End If
 
P

Paul Conroy

Hi Rod,

Alas, replacing the object with pj also does not work. Removing the lines
below is the only work-around I have found.

'check whether the plan has been previsouly saved
If pj.LastSaveDate <> "" Then
'was any previous save less than 15 mins ago
If DateDiff("n", pj.LastSaveDate, Now) < 15 Then

It's no big deal, I'm simply curious as to why it occurs.

Paul
--
Please rate this post if it has helped

http://theprojectserverguru.spaces.live.com


Rod Gill said:
Hi,

Does replacing:
If ActiveProject.LastSaveDate <> "" Then

with

If pj.LastSaveDate <> "" Then

Work?

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
R

Rod Gill

The only other thing to try is:
DateDiff("n", cdate(ActiveProject.LastSaveDate), Now)

I suspect that the LastSaveDate value is not being recognised as a date by
the DateDiff function under some circumstances. The convert to date function
will either work or return 1900 so the interim request won't work, but the
ode shouldn't fail.

On Error Resume Next
at the beginning will also help.
--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com



Paul Conroy said:
Hi Rod,

Alas, replacing the object with pj also does not work. Removing the lines
below is the only work-around I have found.

'check whether the plan has been previsouly saved
If pj.LastSaveDate <> "" Then
'was any previous save less than 15 mins ago
If DateDiff("n", pj.LastSaveDate, Now) < 15 Then

It's no big deal, I'm simply curious as to why it occurs.

Paul
 
P

Paul Conroy

using the cdate function didn't fix the problem, but adding the error
trapping did bypass it successfully.

Thanks

Paul
 

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