Welcome to MapForums!

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

## How to calculate distance between 2 location with vba

This is a discussion on How to calculate distance between 2 location with vba within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi , i have map point 2004 and access, and i want to take data in my, db 2 locations ...

1. Junior Member White Belt
Join Date
Feb 2004
Posts
3

## How to calculate distance between 2 location with vba

Hi , i have map point 2004 and access, and i want to take data in my, db 2 locations and i want that map point calculate the distance and give me back the result so i can store it in my db.

how can i automate this ???

2. Junior Member White Belt
Join Date
Feb 2004
Posts
3
Here is the code to do that (distance between 2 Postal Code (Zip) ) i finaly find it

Code:
```Sub GetKm&#40;&#41;
Set oApp = New MapPoint.Application
Set oMap = oApp.NewMap
Set oLoc&#40;1&#41; = oMap.FindAddressResults&#40;"", "mons", , , "7000", "Belgium"&#41;
Set oLoc&#40;2&#41; = oMap.FindAddressResults&#40;"", "namur", , , "5000", "Belgium"&#41;
Set Loca&#40;1&#41; = oLoc&#40;1&#41;.Item&#40;1&#41;
Set Loca&#40;2&#41; = oLoc&#40;2&#41;.Item&#40;1&#41;

If Not oLoc&#40;1&#41; Is Nothing Then      'Check to see if the first address was found.
If Not oLoc&#40;2&#41; Is Nothing Then      'Check to see if the second address was found
Debug.Print oMap.Distance&#40;Loca&#40;1&#41;, Loca&#40;2&#41;&#41;
End If
End If
Set oMap = Nothing
Set oApp = Nothing
End Sub```