PDA

View Full Version : MapPoint API fails after fourth GPX export



Brian
05-07-2014, 01:48 PM
I understand that the Access folks will probably say that this is a MapPoint issue, and vice versa, but this forum is the closest thing to getting both in one place and they are, after all, both MS products.


I am using Access 2010 (and Access 2003 before that) to programmatically send addresses to MapPoint 2010/2011/2013, route & optimize them, then record stop numbers back into my DB. If, while a map is open, I then do a certain function in MapPoint (export the map to a GPX file three times), with or without other interaction via VBA or the MP GUI in between, I get this error in Access (VBA) upon the next programmatic interaction with the open map: Automation error. The interface is unknown.


Here is the VBA environment:


Variable appMapPoint is a public object variable, since various forms in my app need to interact with the currently-open map. It is dimensioned thus:


Public appMapPoint As Object


Then there is a public sub used to open MapPoint. The germane line of code is this:


Set appMapPoint = CreateObject("MapPoint.Application")


Now, in my form where I have the problem, I send the addresses to the map. Then (in MapPoint) click Data -> Export to GPX and save the GPX file (four times--and this is not just me being clever; this was discovered by a user that needs to export various data sets independently from the same map). Then I run the bit of code below (or any other code that references any property of the MP application object):


If appMapPoint Is Nothing Then Exit Sub 'exit if the user closed the map from the MapPoint user interface
Dim MapCurrent As Object
Set MapCurrent = appMapPoint.Application.ActiveMap
MapCurrent.DataSets.ZoomTo
Set MapCurrent = Nothing


I have traced it down to failing when it hits the third line:


Set MapCurrent = appMapPoint.Application.ActiveMap


In fact, if I put this line just before it, I get the error here instead:


MsgBox "appMapPoint.Application.Version: " & appMapPoint.Application.Version 'or .Name or any other property


The first line always recognizes that the MapPoint application object still exists (i.e. it is not Nothing), but the third line does not recognize any of its properties. I assume this means that the object still exists, but Access is unable to communicate with it. This happens whether I do my GPX exports all at once or whether I intersperse them with other code interaction (like Zoom to Data) in between each GPX export: the first automation attempt after the fourth GPX export always fails.

Eric Frost
05-08-2014, 08:03 AM
Hi Brian,

Thanks for your post.

I have a feeling there's something else going on, but I think I'd have to play with the whole app to track it down.

e.g. I would look for: does appMapPoint somewhere go out of scope or get redefined?
Maybe a inserting a line like this would be a work-around?

Set appMapPoint = GetObject(,"MapPoint.Application")
Dim MapCurrent As Object
Set MapCurrent = appMapPoint.Application.ActiveMap
MapCurrent.DataSets.ZoomTo
Set MapCurrent = Nothing

Good luck and let us know how it goes!

Eric

Brian
05-10-2014, 09:56 AM
Hi, Eric.

I modified it as you suggested:

Dim MapCurrent As Object
Set appMapPoint = GetObject(, "MapPoint.Application")
Set MapCurrent = appMapPoint.Application.ActiveMap
MapCurrent.DataSets.ZoomTo
Set MapCurrent = Nothing

This all runs fine--except after the fourth GPX export on the map. That is, I send points to the map, then I go to the map GUI and (four times) click Data -> Export to GPX File & save the file, then click any function that refers to any property of the MapPoint application, and it fails. Now, though, the message is this:

Error number 429: ActiveX component can't create object. [This is now occurring on your new line of code GetObject...]

So far, I remain mystified. I will try to post a drastically trimmed-down version of the app shortly.

Brian
05-10-2014, 10:49 AM
Hi, Eric.

I have trimmed a copy of my app down to perhaps 5% of its original size, removing everything except the elements involved in this process and the bare prerequisites. I have attached it here. It is in Access 2010 format.

Here is what I removed:



All references to the live data , which resides in a MySQL DB on a web server and is retrieved and updated via ODBC
All error trapping. I normally trap events such as this (among many others): error -2147418113 that occurs when a user cancels the save in the MapPoint interface when the GPX export was spawned from VBA
Handling of all addresses not found during the process of locating addresses on the map. For this app, I just used some local Home Depot addresses and verified that they would not error out.
All public variables and code. I moved this into the module of the form to prevent any potential issues surrounding global/public variables. The only change in behavior is that it now takes five iterations (up from four) of the GPX export before the MapPoint application object is lost to my app.
All status bar management. Due to the length of time some mapping functions take, I make extensive use of status bar updates to tell the user which step is underway and, where possible, use a progress bar so the user knows how things are progressing. For example, when locating addresses on the map, I set up a progress bar based on the number of addresses in the underlying recordset, then increment the bar as I loop through the addresses to run them through the .FindAddressResults method.
Many other modules, forms, queries, and reports.
Most of the controls on the one form I retained here and all code associated with them.


I have also decompiled, compacted/repaired and recompiled the code.


Here is how to produce the issue:




Open my app
Open the Routing form
Click Send to map
Click OK at the message indicating the map is ready.
In MapPoint, click Data -> Export to GPX file, then enter a filename and click Save
In my app, click Zoom to Data or Optimize (not a critical step--this is just to demonstrate that this part does work before the steps below)
Repeat the two steps above four more times. You can save as a new GPX each time or just save over the prior one; it makes no difference.
(Alternatively, do just the GPX step a total of five times in MapPoint, and then click Zoom to Data or Optimize in my app).
After the fifth export to GPX, the interface is lost.


Alternatively, you can use the Export to GPS button on my form to spawn the GPX export process. While this still requires the browse & save in MapPoint, it saves the trouble of clicking Data -> Export to GPX in MapPont. This is not convenient with a single monitor, but with dual monitors this feature is a timesaver. When duplicating the problem this way, the fifth iteration of Export to GPX will simply hang MapPoint with no error. If instead I do the fifth iteration of the GPX export from within MapPoint, the next Zoom or Optimize will fail.

The issue happens in MP2011 as well as MP2013. I just upgraded to MP2013 specifically to see if it would solve this issue.

Brian
05-11-2014, 12:44 AM
Please cross-reference this thread on the Access developers' forum, where I think I exhausted all possibilities of the problem being in my application: Error: "The interface is unknown". (http://social.msdn.microsoft.com/Forums/office/en-US/f6a8ab2c-de55-4701-95de-2ebdcea06a1c/error-the-interface-is-unknown?forum=accessdev).

That is, I really do think this is a bug, and as specific as the conditions are under which it occurs, one of my clients uncovered it and needs it to work (open map programmatically, multiple GPX exports from MapPoint, followed by further programmatic interaction--the exact situation that triggers the error).

But how do I go about contacting Microsoft about a bug in MapPoint and how do they release fixes? I cannot see that it is like Office, where they release updates and service packs regularly.

Brian
05-13-2014, 03:14 PM
In answer to your specific question, "does appMapPoint somewhere go out of scope or get redefined?": I think this one is a fairly straightforward "no". Not only has the code been working in all other respects for six years, but all my code, including the portion posted here, works perfectly except after the user does multiple GPX exports within the MapPoint GUI while the map is open.

My guess is that any application that spawns MapPoint, then (based on user input in the external application) interacts with the MapPoint application or its objects would fail in like manner after five GPX exports inside the MapPoint GUI.


Hi Brian,

Thanks for your post.

I have a feeling there's something else going on, but I think I'd have to play with the whole app to track it down.

e.g. I would look for: does appMapPoint somewhere go out of scope or get redefined?
Maybe a inserting a line like this would be a work-around?

Set appMapPoint = GetObject(,"MapPoint.Application")
Dim MapCurrent As Object
Set MapCurrent = appMapPoint.Application.ActiveMap
MapCurrent.DataSets.ZoomTo
Set MapCurrent = Nothing

Good luck and let us know how it goes!

Eric