Microsoft KB Archive/236615

= How To Automate MapPoint 2000 from Visual Basic =

Article ID: 236615

Article Last Modified on 8/23/2005

-

APPLIES TO


 * Microsoft MapPoint 2000 Standard Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q236615



SUMMARY
This article demonstrates how to automate Microsoft MapPoint 2000 from Microsoft Visual Basic to find an address and to add a pushpin at that address.

Note The sample code that is included in this article only works with MapPoint 2000. The Visual Basic Object Model has changed in MapPoint 2001.



Building the Automation Sample
 Start Visual Basic and create a new standard EXE project.

Form1 is created by default. Add a Command button to Form1. Click References on the Project menu to bring up the References dialog box. Add a reference to the Microsoft MapPoint 1.0 Object Library and then click OK to close the References dialog box.  Insert the following code in the code window for Form1: Option Explicit

Private Sub Command1_Click ' Declare variables Dim oApp As MapPoint.Application Dim oMap As MapPoint.Map Dim oPush As MapPoint.Pushpin ' Create an instance of MapPoint. Set oApp = CreateObject("MapPoint.Application")

' Add a new map. Set oMap = oApp.NewMap

' Find a specific address. oMap.Find ("1 Microsoft Way, Redmond, WA")

' Select the pushpin at the above address. Set oPush = oMap.FindPushpin("1 Microsoft Way")

' Go to that pushpin, change its name, and highlight it. oPush.GoTo oPush.Name = "Microsoft" oPush.Highlight = True

' Release references. Set oPush = Nothing Set oMap = Nothing Set oApp = Nothing End Sub  Press F5 to run the project.

When you click the Command button, you see MapPoint start and then put a highlighted pushpin at Microsoft.</ol>

<div class="references_section">