converting decimal degrees to degrees, minutes, seconds

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way in MS Access to input decimal degrees and have it convert to
degrees minutes seconds. Expression builder doesn't like any of the variation
I have tried. Can it be done in Expression builder, as a macro, or is there
another way to do it.

Thanks
Dave
 
That would be nice, but I think you may have to write a function that
converts for you (and probably represent it as a string). Here is one way, as
an example. I just sent the output to message boxes, both as literals and
using the degree/minute/second symbols:

Dim DecDeg As Double
Dim DecMin As Double
Dim Deg As Integer
Dim Min As Integer
Dim Sec As Integer
Dim DMS As String
DecDeg = InputBox("Enter degrees.")
Deg = Int(DecDeg)
DecMin = (DecDeg - Deg) * 60
Min = Int(DecMin)
Sec = Round((DecMin - Min) * 60, 0)
DMS = Str(Deg) & " degrees " & Str(Min) & " minutes " & Str(Sec) & " seconds"
Msgbox "Literals: " & DMS
DMS = Str(Deg) & Chr(186) & " " & Str(Min) & "' " & Str(Sec) & """"
Msgbox "Symbols: " & DMS
 
Thanks Brian, that works, but now how do I get it to populate the table field
"Latitude", with the converted data?
 
I can think of a couple of approaches. The first will store the information
as numbers, while the second will store the information as the resulting text
string:

For either of them, create a module with this public function in it:

Function DegreeConv(DecDeg As Double) As String
Dim Deg As Integer
Dim DecMin As Double
Dim Min As Integer
Dim Sec As Integer
Deg = Int(DecDeg)
DecMin = (DecDeg - Deg) * 60
Min = Int(DecMin)
Sec = Round((DecMin - Min) * 60, 0)
DegreeConv = Str(Deg) & Chr(186) & " " & Str(Min) & "' " & Str(Sec) & """"
End Function

1. Just store the decimal degrees and have the function run when you want to
see one of them in the proper format (e.g. when displaying on a form or in a
report), since I do not believe that there is a standard format for storing
angles or lat/long values. If you have a form that has two boxes: DecDeg and
Latitude, this code will correctly populate Latitude from the DecDeg.

Private DecDeg_AfterUpdate()
Latitude = DegreeConv(DecDeg)
End Sub

2. Store the resulting text string. To do this one, I started with a VERY
simple table called Degrees. It has only two fields: DecDeg (Number, Double)
and Latitude (Text). Create a few records with entries in DecDeg but leave
Latitude blank.

Now create a new query, go to SQL view, and past this into it:

UPDATE Degrees SET Degrees.Latitude= DegreeConv([DecDeg]);

When you run the query, it will update the latitude field to match the
decimal degrees.

The only drawback is that the data is stored as a string, not as a number.
You may wish to store both, as in my simple example, so that you can use the
numeric value in calculations, but the latitude string when displayed for
users.
 
Back
Top