Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map to Mappoint from Access Form

Status
Not open for further replies.

TaylorTot

Technical User
Dec 23, 2003
96
US
Hello,

I have an access form that runs a query based on an address entered by
the end user. The query returns all vendors within 15 miles. I have
been successful in mapping the results of the query, but I would also
like to map the address that is entered in the form. . . this is where
I'm having trouble. Below is the code I am using to map the query
results. Can someone tell me how I can get the address entered to map
also (with different symbol).

Code:
Sub MapSelectedProperties() 
  'Map the selected properties 
  On Error GoTo MapSelectedProperties_Err_Exit 
  Dim db As Database 
  Dim rstProps As DAO.Recordset 
  Dim qdf As QueryDef 


  Dim objLoc As MapPoint.Location 
  Dim objMap As MapPoint.map 
  Dim objPushPin As MapPoint.Pushpin 


  Dim strMsg As String 
  Dim i As Integer 
  i = 0 
  Set db = CurrentDb() 


  'Load the selected properties into a recordset 
  Set qdf = CurrentDb.QueryDefs("Get20Mile_SelQry") 
  qdf.Parameters(0) = Forms![frmMain]![txtZipCode] 
       Set rstProps = qdf.OpenRecordset(dbOpenDynaset) 
        Set Recordset = rstProps 


  'Make sure at least one property was selected 
  If rstProps.RecordCount > 0 Then 
    'Load Map 
    If LoadMap() Then 
      'Open the form containing the map 
      FormOpen "frmMap" 
      Set objMap = gappMP.ActiveMap 
      'Place a pushpin on the map for each selected property 
      While Not rstProps.EOF 
        i = i + 1 
        Set objLoc = objMap.FindAddressResults(rstProps!Address1, 
rstProps!City, , rstProps!StateCode, rstProps!Zip)(1) 
        Set objPushPin = objMap.AddPushpin(objLoc, rstProps!Address1) 
        objPushPin.Name = CStr(i) 
        objPushPin.Note = rstProps!CompanyName 
        objPushPin.BalloonState = geoDisplayBalloon 
        objPushPin.Symbol = 77 
        objPushPin.Highlight = True 
        rstProps.MoveNext 
      Wend 
      'Show all pushpins on the map display 
      objMap.DataSets.ZoomTo 
    Else 
      strMsg = "Unable to load map." 
      MsgBox strMsg, vbOKOnly + vbExclamation, APP_NAME 
    End If 
  Else 
    strMsg = "No properties selected." 
    MsgBox strMsg, vbOKOnly + vbExclamation, APP_NAME 
  End If 
MapSelectedProperties_Err_Exit: 
  On Error Resume Next 
  Set objPushPin = Nothing 
  Set objLoc = Nothing 
  Set objMap = Nothing 
  If Not (rstProps Is Nothing) Then rstProps.Close 
  db.Close 
  Exit Sub 
MapSelectedProperties_Err: 
  Resume MapSelectedProperties_Err_Exit 
End Sub

Thanks for your help in advance

 
TaylorTot,
Something like (assumes your form has the same fields as the recordset and are prefixed by [tt]txt[/tt]):

Code:
...
  'Make sure at least one property was selected
  If rstProps.RecordCount > 0 Then
    ...
  End If
[b]  Set objLoc = objMap.FindAddressResults([i]Me.txtAddress1[/i], _
                                       [i]Me.txtCity[/i], _
                                       , _
                                       [i]Me.txtStateCode[/i], _
                                       [i]Me.txtZip[/i])(1) 
  Set objPushPin = objMap.AddPushpin(objLoc, [i]Me.txtAddress1[/i])
  With objPushPin
    .Name = [i]Me.txtAddress1[/i]
    .Note = "[i]Center of search radius[/i]"
    .BalloonState = geoDisplayBalloon
    .Symbol = 77
    .Highlight = True
  End With[/b]
MapSelectedProperties_Err_Exit: 
...

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Wow, again you have saved me! Thanks so much for your help!
 
TaylorTot,
Glad to hear it worked, I feel it's only fair to let you know that I don't know a thing about MapPoint :)

Really.

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top