I would like to be able to generate a MapPoint 2001 route map using
automation from within Access. Using the routine below, attached to a
button on a form, I can generate directions between two points, paste those
into the clipboard and the paste them into a text box on the form.
1. Is there a similar way to generate a map?
2. How come the pushpin I add is not added to the My Pushpin dataset when I
open the map in MapPoint? How can I open MapPoint and display the route?
3. I use the On Error if the address fails. Is there another way to test
for a failure?
============================================
Private Sub cmdFindAddress_Click()
Dim oApp As MapPoint.Application
Dim oMap As MapPoint.Map
Dim oPush As MapPoint.Pushpin
Dim oLoc(1 To 2) As MapPoint.Location
Dim strLoc As String, strName As String
On Error GoTo cmdFindAddress_err
'take the customer address to find from the form
strLoc = Me!Str_Address1 & "," & Me!City & "," & Me!STATE
'use customer name for pushpin name
strName = Me!Res_Last_Name & "_" & Me!Job_ID
Set oApp = New MapPoint.Application
'open map centered in client location
Set oMap = oApp.OpenMap("Grapevine Area, Texas, United States.ptm")
'find client location
Set oLoc(1) = oMap.Find("340 W Northwest Highway, Grapevine, TX")
'find customer location
Set oLoc(2) = oMap.Find(strLoc)
'place a pushpin at the customer location
Set oPush = oMap.AddPushpin(oLoc(2), strName)
'create and calculate a route from client to customer
With oApp.ActiveMap.ActiveRoute
.Waypoints.Add oLoc(1), "Classic Tile Main Office"
.Waypoints.Add oLoc(2), strName
.Calculate
End With
'copy the route directions to clipboard and paste to textbox on form
oApp.ActiveMap.CopyDirections
Me!txtDirections.SetFocus
DoCmd.RunCommand acCmdPaste
cmdFindAddress_exit:
Set oPush = Nothing
Set oMap = Nothing
Set oApp = Nothing
Set oLoc(1) = Nothing
Set oLoc(2) = Nothing
Exit Sub
cmdFindAddress_err:
MsgBox " Address not found."
Resume cmdFindAddress_exit
End Sub