MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Crashes Access when closes

This is a discussion on Crashes Access when closes within the MapPoint 2006/2009 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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-26-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 01-27-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,112
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
access, closes, crashes


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Disabling the Save Pop up when application closes Anonymous MapPoint 2006/2009 Discussion 2 02-10-2005 11:58 PM
MDI - Map closes! Anonymous MapPoint 2006/2009 Discussion 0 08-25-2004 11:44 AM
Help crashes glshrike MapPoint 2006/2009 Discussion 1 02-03-2004 02:57 PM
Finding Closes Intersection Sylvain MapPoint 2006/2009 Discussion 1 05-14-2003 06:08 PM
Control Crashes - Help !!! dougw MapPoint 2006/2009 Discussion 1 04-10-2003 09:29 AM


All times are GMT -5. The time now is 07:29 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map


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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54