View Full Version : Unable to add stops to route

10-04-2012, 09:41 AM
I am using VBS to create a route plan and get the distance and time data for various routes.

MapRoute.Waypoints.Add MapPointMap.FindResults(WS.Cells(CheckRow, 4) + ", " + WS.Cells(CheckRow, 5) + ", " + WS.Cells(CheckRow, 6) + ", " + WS.Cells(CheckRow, 7)).Item(1)

This is the code I'm using in a loop. The Cell references are parts of various addresses.
When run, this code works twice and then stops. All my routes in Mappoint consist solely of a beginning stop and ending stop, and I don't know why. Anyone have any ideas?

Eric Frost
10-04-2012, 12:01 PM
I don't know.. what is the address where it fails? What is the error?

10-04-2012, 12:56 PM
There is no error or failure. There is only a lack of function. Again, the loop works twice and then stops. The whole thing gets reset automatically for another route and then it again works twice and then doesn't work again.

Eric Frost
10-04-2012, 01:43 PM
Can you post more of the code including the loop or a sample or stripped down macro and sheet that exhibits the problem?

I could be wrong, but I don't think your issue is that particular line of code.


10-05-2012, 07:53 AM
You are blindly using FindResults without checking the results are valid - this is very bad practice. FindResults is NOT an array, but an object. This has a "ResultsQuality" property which tells you whether the results were found, whether they were ambiguous or not.

Check this property first before accessing individual results from the object. You'll probably find MapPoint cannot geocode one of your addresses.