View Full Version : MapPoint inconsistently failing to match waypoint/pushpin names

05-02-2014, 02:14 PM
MapPoint 2011.

I have several pages of VBA code that, in part, does this:

1. Sends addresses to the map as pushpins, with an option to automatically route and/or optimize.
2. Waits for the user to route and optimize all or some of the points.
3. On click of a button in my Access application, updates the external database by recording the newly-assigned stop numbers, then continues with the next two steps.
4. Deletes the already-routed waypoints, along with pushpins whose names match the names of those waypoints. This gets them off the map so the user can see if he missed any points and/or continue routing the rest of the points on the map.
5. Closes the map if there are no more pushpins remaining on the map (i.e. user has routed all the points).

The problem occurs in this bit of code that occurs in #4 above. Except for LocationName (string), the variables are all object variables, and they all work correctly.

For Each WaypointCurrent In RouteCurrent.Waypoints
Set LocationCurrent = WaypointCurrent.Location
LocationName = LocationCurrent.Name
Set PushPinCurrent = MapCurrent.FindPushpin(LocationName)
If Not PushPinCurrent Is Nothing Then PushPinCurrent.Delete 'avoids error; if user moved waypoint, there will be no matching pushpin

You can see that I get the name of the waypoint, then find the pushpin with a matching name--which should be simple because the waypoint inherited its name from the pushpin when it was created in step #2 above. However, MapPoint inconsistently fails to create the reference to the pushpin having the same name as the waypoint.

The scale of the problem is small but fairly persistent. In today's testing, there is one address of 60 that fails consistently and a few others that depending on a variety of seemingly unrelated factors. For instance, if I pop up a message box to show the name of the waypoint and/or, the consistent one works and one or two others fail (different ones different times). And yesterday, when a user was actually using my app with these exact same addresses (one time through his process), the "problematic" address and three other pushpins got left on the map.

Any ideas?

05-05-2014, 08:58 AM
Our MPRouteWriter product ( RouteWriter: Export Routes from Microsoft MapPoint (http://www.mproutewriter.com) ) does something very similar, and it works.

The only time FindPushpin might give the wrong result is if the pushpin name is non-unique. Then, MapPoint will return the first it finds - it has no idea which you actually want!

05-06-2014, 12:05 PM
I know it should work, but it does not work consistently. Even with a single pushpin on the map (i.e. a specific address of a few that are problematic), this code fails to delete it:

LocationName = WaypointCurrent.Name
Set PushPinCurrent = MapCurrent.FindPushpin(LocationName)

However, the same exact pushpin is deleted every time using the code below:

LocationName = WaypointCurrent.Name
For Each dsMapPoint In MapCurrent.DataSets
Set rsMapPoint = dsMapPoint.QueryAllRecords
Do While Not rsMapPoint.EOF
Set PushPinCurrent = rsMapPoint.Pushpin
PushPinName = PushPinCurrent.Name
If PushPinName = LocationName Then 'pin name matches waypoint name
End If
Next dsMapPoint

Why, given the same exact search string, can it find the pushpin by its name as a member of the dataset but not using FindPushPin--but only that one point out of 68 in today's example? It is consistent in that it is the same points that fail but inconsistent in that changing the method of identifying the pushpin changes the result.

05-07-2014, 09:39 AM
Probably because you are deleting a pushpin from within a recordset.

You'll have the same problem if you iterate over shapes and delete a few - it will mess the iterators up.

So loop over, find the ones you want to delete, keep references to them, and then delete them after the recordset is finished and closed.

05-07-2014, 04:06 PM
Can you please explain "iterators"? There is no explicit recordset open in my code at the point at which this code is running. Are you saying that the FindPushpin method uses an implicit recordset made up of all DataSets on the map and that this recordset is static?

I can understand the concept of an implied recordset but not one that is static. Much of the usefulness of the MapPoint API (and functionality in my various MapPoint-related applications) depends heavily on the successful deletion of waypoints and pushpins from the Waypoints collection and Dataset object, respectively, without affecting subsequent references to the Waypoints collection and parent Dataset object.