Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

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

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 2 of 2

Crashes Access when closes

This is a discussion on Crashes Access when closes within the MapPoint Desktop Discussion forums, part of the Map Forums category; I have a form in Access that plots our oil well records within a specified distance from a center point ...

  1. #1
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Crashes Access when closes

    I have a form in Access that plots our oil well records within a specified distance from a center point using Mappoint. Everything works except -
    1. Access crashes when you go to close it.
    2. You can only run the plot once w/o closing access. If I try to run the mapping feature more than once, I get an error message- Method 'Distance' of object '_Map' failed.
    3. I'd like to turn off the Save Map msgbox at the end of the application.

    I am using Gilles Kohl to obtain the lat & long of the location (in this case county), then find records within specified distance based on that and entered tolerance on Access form.


    Private Sub cmdFindCounty_Click()
    On Error GoTo Err_cmdFindCounty_Click

    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim oApp As Object
    Dim oMap As Object
    Dim strPushpinSetName As String
    Dim strSQL As String
    Dim strNote As String
    Dim dblLat As Double
    Dim dblLon As Double
    Dim dbtolerance As Double
    Dim dbLatNorth As Double
    Dim dbLatSouth As Double
    Dim dbLongEast As Double
    Dim dbLongWest As Double
    Dim dbDistance As Double
    Dim shapeCreated As Boolean
    Dim oDS As MapPoint.DataSet
    Dim oDataSet As MapPoint.DataSet
    Dim oRecordset As MapPoint.Recordset
    Dim oLoc As MapPoint.Location
    Dim oLocTst As MapPoint.Location
    Dim oPin As MapPoint.Pushpin
    Dim oPush1 As MapPoint.Pushpin


    Set oApp = CreateObject("MapPoint.Application")
    Set oMap = oApp.NewMap
    dbtolerance = Me.txtTolerance

    Set oLoc = oMap.Find(txtCounty & " County, " & cboState)
    If Not oLoc Is Nothing Then
    Set oPush1 = oMap.AddPushpin(oLoc, UCase(txtCounty) & " County, " & cboState)
    oPush1.BalloonState = geoDisplayBalloon
    oPush1.Symbol = 25 'Change pushpin symbol to red dot
    oPush1.Highlight = True
    oPush1.Note = "Center of Search Radius."
    oPush1.Goto
    End If

    Call CalcPos(oMap, oLoc, dblLat, dblLon) 'Return lat and long by reference

    'A degree of latitude is always ~ 69miles. Using 1/68 of a degree
    'per mile ensures that the rectangle is slightly larger than the radius desired.
    dbLatNorth = dblLat + (CDbl(dbtolerance) / CDbl(6)
    dbLatSouth = dblLat - (CDbl(dbtolerance) / CDbl(6)

    'A degree of longitude varys based on nearness to the equator or the poles.
    'Used ~55 miles . Using 1/55 of a degree in equations.
    dbLongEast = dblLon + (CDbl(dbtolerance) / CDbl(55))
    dbLongWest = dblLon - (CDbl(dbtolerance) / CDbl(55))

    Set rs = New ADODB.Recordset
    'Create recordset based on latitude and longitude tolerances.
    Set rs.ActiveConnection = CurrentProject.Connection
    strSQL = "SELECT tblBitRecord.WellOperator, tblBitRecord.WellName, "
    strSQL = strSQL & "tblBitRecord.SpudDate, tblBitRecord.Latitude, tblBitRecord.Longitude "
    strSQL = strSQL & "FROM tblBitRecord "
    strSQL = strSQL & "WHERE tblBitRecord.Longitude BETWEEN " & dbLongWest & " AND " & dbLongEast
    strSQL = strSQL & "AND tblBitRecord.Latitude BETWEEN " & dbLatSouth & " AND " & dbLatNorth
    With rs
    .CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .Open strSQL
    End With

    'Create a new pushpin set
    strPushpinSetName = "Locations within " & CStr(Me.txtTolerance) & _
    " miles of selected county"
    oMap.DataSets.AddPushpinSet strPushpinSetName
    Set oDS = oMap.DataSets(strPushpinSetName)
    oDS.Select

    Do While Not rs.EOF
    Set oLocTst = oMap.GetLocation(rs!latitude, rs!Longitude)
    'This adds the pushpins to the "My Pushpins" set.
    Set oPin = oMap.AddPushpin(oLocTst, rs!WellName)
    'strNote = rs!WellOperator & " - " & rs!WellName
    dbDistance = oMap.Distance(oLoc, oLocTst)
    strNote = rs!WellOperator & " - " & rs!WellName & ": " & Format(dbDistance, "##,##0.00") & " mi"
    'objPin.BalloonState = geoDisplayName
    oPin.BalloonState = geoDisplayBalloon
    oPin.Note = strNote
    'Cut and paste the pushpin into the new set.
    oPin.Cut
    oDS.Paste
    rs.MoveNext
    Loop

    On Error Resume Next
    oDS.Symbol = 25
    oDS.DisplayDataMap DataMapType:=geoDataMapTypePushpin
    oDS.ZoomTo
    oDS.Name = strPushpinSetName
    Set oRecordset = oDS.QueryAllRecords
    oRecordset.MoveFirst
    Do Until oRecordset.EOF
    Set oLocTst = oRecordset.Pushpin.Location
    'Use the distance method to find the distance between a pushpin and the reference point.
    dbDistance = oMap.Distance(oLoc, oLocTst)
    'If the pushpin is outside of the desired distance, change the color of the symbol.
    If dbDistance > dbtolerance Then
    oRecordset.Pushpin.Symbol = 30 'green circle
    Else
    oRecordset.Pushpin.Symbol = 25 ' red circle
    End If
    oRecordset.MoveNext
    Loop

    oMap.Altitude = dbtolerance * 7.5

    oMap.Shapes.AddShape geoShapeRadius, oLoc, dbtolerance * 2, 1000 'dbTolerance * 2
    oMap.Shapes.Item(oMap.Shapes.Count).Name = "Bit Record Tolerance"
    oMap.Shapes.Item(oMap.Shapes.Count).Line.Weight = 2
    oMap.Shapes.Item(oMap.Shapes.Count).Line.ForeColor = vbBlack
    oMap.Shapes.Item(oMap.Shapes.Count).Fill.Visible = True
    oMap.Shapes.Item(oMap.Shapes.Count).Fill.ForeColor = RGB(185, 187, 185)
    oMap.Shapes.Item(oMap.Shapes.Count).ZOrder geoSendBehindRoads

    shapeCreated = True

    'Place the map into Access
    oMap.CopyMap
    imgClip.Visible = True
    imgClip.Action = acOLEPaste

    lblMapInfo.Caption = strPushpinSetName

    rs.Close
    Set rs = Nothing
    Set cn = Nothing
    Set oLoc = Nothing
    Set oLocTst = Nothing
    Set oPin = Nothing
    Set oRecordset = Nothing
    Set oDS = Nothing
    Set oDataSet = Nothing
    Set oMap = Nothing
    Set oApp = Nothing
    Me.SetFocus

    Exit_cmdFindCounty_Click:
    Exit Sub

    Err_cmdFindCounty_Click:
    MsgBox Err.Description
    Resume Exit_cmdFindCounty_Click

    End Sub

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    I can only answer (3):

    Code:
                if (MP.ActiveMap != null)
                    MP.ActiveMap.Saved = true;
    1. Maybe it help if you describe exacly what you means by 'crash'. Can you determine if something crash in your code or is it access ? If it is you code can you tell the exact line where it happens ?

    I'm not myself famiilisar with VB, but some extra information is probably very usefull.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Disabling the Save Pop up when application closes
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 02-10-2005, 11:58 PM
  2. MDI - Map closes!
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 08-25-2004, 11:44 AM
  3. Help crashes
    By glshrike in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 02-03-2004, 02:57 PM
  4. Finding Closes Intersection
    By Sylvain in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 05-14-2003, 06:08 PM
  5. Control Crashes - Help !!!
    By dougw in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-10-2003, 09:29 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25