VB code from a 9.3mxd not running in 10 - sort of

355
2
12-10-2010 09:04 AM
RobertFriedel
New Contributor II
some code I had written in 9.3 that is embedded in an mxd and is supposed to run when the mxd is opened does not work in 10.  It's very simple code, all it does is update a small string of text in the layout with details about the document: name, path, size, etc... 

When I open the mxd in 10 (SP1) I get the run-time error 91 'object variable or with block variable not set'. But when I go to debug the code, and hit run in the vb editor, all runs fine and the text updates as it should. 

I'm really a hack with arcobjects and I'm sure this is probably a very simple, very easy fix but it's just beyond me.  I've attached the mxd for reference.  Can anyone shed some light on this?

Rob
0 Kudos
2 Replies
JeffreyHamblin
New Contributor III
I reproduced the same behavior you describe. It is caused by this line:

Private Function MxDocument_OpenDocument() As Boolean
...
  Set pEnumElement = pGraphicsContainer.LocateElements(pPoint, 0.2)
...


pGraphicsContainer.LocateElements(pPoint, 0.2) is returning null (nothing) when called by OpenDocument().

It makes me think the page layout isn't fully initialized before OpenDocument() is triggered. In fact, if you add a 5 second sleep as the first line of the MxDocument_OpenDocument() function, the page layout is blank during that period, and the error still occurs.

Seems like a bug. Maybe an Add-in extension would be better than VBA? (assuming OpenDocument() doesn't exhibit the same behaviour there...).

-Jeff
0 Kudos
RobertFriedel
New Contributor II
Jeff,

Thanks for taking a shot, I appreciate the insight.  I guess it's that time to write to ESRI and hope sp2 covers this.  Have a good one

Rob
0 Kudos