Error 91: Object variable or With block variable not set

C

carjer

Hi. can you help me please?

I created a macro in MS Project 2003. When I execute macro, the MS
project displays the following error:
"Error 91: Object variable or With block variable not set"

When I run debug I see error in "if" but I do not understand what it
means.

Can you please check my code?
Thanks in advance & Happy New Year!
Regards


Private Sub App_ProjectBeforeSave(ByVal pj As Project, ByVal SaveAsUi
As Boolean, Cancel As Boolean)
'MsgBox "" & pj.ProjectSummaryTask.EnterpriseProjectDate3

If (pj.ProjectSummaryTask.EnterpriseProjectCost10 <
pj.ProjectSummaryTask.BaselineCost And
pj.ProjectSummaryTask.EnterpriseProjectCost10 <> 0) Or
(pj.ProjectSummaryTask.EnterpriseProjectDate3 >
pj.ProjectSummaryTask.BaselineStart And
pj.ProjectSummaryTask.EnterpriseProjectDate3 <> "NA") And
(pj.ProjectSummaryTask.EnterpriseProjectDate2 <
pj.ProjectSummaryTask.BaselineFinish Or
pj.ProjectSummaryTask.EnterpriseProjectDate2 <> "NA") Then

MsgBox "Error with save Baseline.", vbCritical
Cancel = True
End If
End Sub
 
J

John

Hi. can you help me please?

I created a macro in MS Project 2003. When I execute macro, the MS
project displays the following error:
"Error 91: Object variable or With block variable not set"

When I run debug I see error in "if" but I do not understand what it
means.

Can you please check my code?
Thanks in advance & Happy New Year!
Regards


Private Sub App_ProjectBeforeSave(ByVal pj As Project, ByVal SaveAsUi
As Boolean, Cancel As Boolean)
'MsgBox "" & pj.ProjectSummaryTask.EnterpriseProjectDate3

If (pj.ProjectSummaryTask.EnterpriseProjectCost10 <
pj.ProjectSummaryTask.BaselineCost And
pj.ProjectSummaryTask.EnterpriseProjectCost10 <> 0) Or
(pj.ProjectSummaryTask.EnterpriseProjectDate3 >
pj.ProjectSummaryTask.BaselineStart And
pj.ProjectSummaryTask.EnterpriseProjectDate3 <> "NA") And
(pj.ProjectSummaryTask.EnterpriseProjectDate2 <
pj.ProjectSummaryTask.BaselineFinish Or
pj.ProjectSummaryTask.EnterpriseProjectDate2 <> "NA") Then

MsgBox "Error with save Baseline.", vbCritical
Cancel = True
End If
End Sub

Carjer,
The error occurs because the object "pj" is not defined completely.
However, I can't duplicate your error. In other words, if I run your
code, it works fine, although I'm not in a Project Server environment
but that shouldn't matter with the type of error you are getting.

You said you are using Project 2003. What updates are installed (i.e.
SP2, SP3)? Did you create the necessary class module to declare the
WithEvents for the new App object? Did you associate the new class
module with the application object? If you don't understand these last
two questions, I suggest you go to fellow MVP, Jack Dahlgren's website
at, http://masamiki.com/project/project_open.htm, and take a look at his
article on "working with events".

By the way, in the future please post VBA questions on our sister
newsgroup, microsoft.public.project.developer.

John
Project MVP
 

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