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)
WaypointCurrent.Delete
If Not PushPinCurrent Is Nothing Then PushPinCurrent.Delete 'avoids error; if user moved waypoint, there will be no matching pushpin
Next
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?