Sorry, it is a procedure, because I am not just returning a single value.
Some of the code has been commented out as I was using it on a different form to invoke MapPoint and determine a location for a different purpose.
Private Sub LatLongCalc(County As String, State As String, zlat As Double, zlong As Double)
'Purpose: To map location based on county and state
'Declarations
Dim oApp As Object, oMap As Object
Dim oPush As MapPoint.Pushpin, oPushA As MapPoint.Pushpin
Dim oLoc As MapPoint.Location, oLocA As MapPoint.Location
'A Mile = 0.01471 Degrees of Lat/Long, a Half mile = 0.007355
Dim Measure As Double
Dim DistX As Double, DistY As Double, DistZ As Double
Dim PointX As MapPoint.Location, PointY As MapPoint.Location
Dim rad As Integer, alt As Integer, I As Integer
Dim strSQL As String
'Assignments
Set oApp = CreateObject("Mappoint.Application"

Set oMap = oApp.ActiveMap
If State = "LA" Then
Set oLocA = oMap.Find(County & " Parish, " & State)
Else
Set oLocA = oMap.Find(County & " County, " & State)
End If
If Not oLocA Is Nothing Then
Set oPushA = oMap.AddPushpin(oLocA)
oPushA.GoTo
'myLat and myLong are a known point. In this case, Wichita, Kansas
myLat = 37.70212
myLong = -97.31775
'Initially, set zLat and zLong equal to the known point
zlat = myLat
zlong = myLong
'Measure is used to adjust the starting distance. In this case, start off with 750 miles.
'Measure is made smaller in the Do While loop below but it is a good idea to start off with a large number
Measure = 0.01471 * 750
'Create two points: oLoc as the reference point and your address for which you need lat/long
Set oLoc = oMap.GetLocation(myLat, myLong)
'Find your address from the form frmLatLong
On Error GoTo endnow 'If there is no address found, then Set oLocA will fail.
Set oLocA = oPushA.Location
On Error Resume Next
X = 0
'Create a loop that will continue until your desired precision. As indicated below this loop will repeat until the lat/long is found to be within 20 feet.
Do While Measure > 0.00005572 'This value is determined using the following formula:
' .01471/5280*Number of Feet for Precision
' Ex: .01471 / 5290 * 20 = .00005572
' Trivia: There are 5,280 feet in a mile.
X = X + 1
'Create two other reference points: PointX is one Measure off oLoc's Latitude. PointY is one Measure off oLoc's Longitude
Set PointX = oMap.GetLocation(zlat + Measure, zlong)
Set PointY = oMap.GetLocation(zlat, zlong + Measure)
'Measure the distances from each of the three reference points to our main address (oLocA)
DistX = oLocA.DistanceTo(PointX)
DistY = oLocA.DistanceTo(PointY)
DistZ = oLocA.DistanceTo(oLoc)
'Determine which reference point is closer to oLocA, our main address
If DistX < DistY And DistX < DistZ Then
'Make the master reference point oLoc equal to PointX since PointX was the closest our main address
Set oLoc = oMap.GetLocation(zlat + Measure, zlong)
zlat = zlat + Measure 'Don't forget to add the Measure to zLat for the next iteration
'Uncomment the next line if you want to see how the algorithm found the lat/long
'Set oPush = oMap.AddPushpin(oMap.GetLocation(zLat + Measure, zLong), x)
End If
If DistY < DistX And DistY < DistZ Then
Set oLoc = oMap.GetLocation(zlat, zlong + Measure)
zlong = zlong + Measure
'Set oPush = oMap.AddPushpin(oMap.GetLocation(zLat, zLong + Measure), x)
End If
If DistZ < DistX And DistZ < DistY Then
'The main reference point is closer than PointX or PointY.
'PointX and PointY were too far away by ADDING a Measure, so here we need
'to subtract a measure from both the Latitude and the Longitude
Set oLoc = oMap.GetLocation(zlat - Measure, zlong - Measure)
zlat = zlat - Measure
zlong = zlong - Measure
'Set oPush = oMap.AddPushpin(oMap.GetLocation(zLat - Measure, zLong - Measure), x)
End If
'Here is where Measure gets adjusted. Check to see if the distance between the new
'reference point is smaller than Measure. If so, reduce Measure by half.
'Don't forget that Measure is in degrees of Lat/Long while the distance will be
'in miles. To convert degrees to miles, multiply by .01471, the number of degrees
'in a mile.
If oLocA.DistanceTo(oLoc) < Measure / 0.01471 Then Measure = Measure / 2
Loop
'Create a PushPin with the new location that matches our address
'Add how many iterations of the loop it took (x) and the the Latitude, Longitude
Set oPushA = oMap.AddPushpin(oLocA, X & ": " & zlat & ", " & zlong)
'For I = 1 To 3
'oMap.Shapes.AddShape(geoShapeRadius, oLoc, radius * 2 * I, radius * 2 * I).Name = "Zone" & CStr(I)
'oMap.Shapes("Zone" & CStr(I)).Adjustments(1) = 45
'Next I
MsgBox "The Lat/Long of your address is " & zlat & ", " & zlong & _
Chr(13) & Chr(13) & "It was found in " & X & " iterations.", _
vbOKOnly, "Lat/Long Results"
'Me.[Latitude] = zlat
'Me.[Longitude] = zlong
'The next four lines are just for presentation. Uncomment them if you like
'oPush.BalloonState = geoDisplayBalloon 'Turn on the balloon state so we can see the lat/long
'oPushA.Highlight = True 'Highlight the pushpin so we really see it
'oMap.DataSets.ZoomTo 'Zoom the map to the individual pushpin
'oMap.Altitude = oMap.Altitude * 15 'alt
'oApp.Visible = True 'Turn on the map so we can see it!
'oApp.UserControl = True
'lblMapInfo.Caption = ""
Else
'lblMapInfo.Caption = "Location Not Found!"
End If
'Set oMap = Nothing
'Set oApp = Nothing
'Me.SetFocus
endnow:
End Sub