converting decimal degrees to degrees, minutes, seconds

Discussion in 'Microsoft Access VBA Modules' started by Guest, Jul 26, 2005.

  1. Guest

    Guest 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
     
    Guest, Jul 26, 2005
    #1
    1. Advertisements

  2. Guest

    Guest Guest

    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

    "DaveN" wrote:

    > 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
    >
     
    Guest, Jul 26, 2005
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    Thanks Brian, that works, but now how do I get it to populate the table field
    "Latitude", with the converted data?

    "Brian" wrote:

    > 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
    >
    > "DaveN" wrote:
    >
    > > 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
    > >
     
    Guest, Jul 26, 2005
    #3
  4. Guest

    Guest Guest

    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.

    "DaveN" wrote:

    > Thanks Brian, that works, but now how do I get it to populate the table field
    > "Latitude", with the converted data?
    >
    > "Brian" wrote:
    >
    > > 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
    > >
    > > "DaveN" wrote:
    > >
    > > > 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
    > > >
     
    Guest, Jul 26, 2005
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Turner

    Convert Seconds to Minutes & Seconds

    Turner, May 1, 2004, in forum: Microsoft Access VBA Modules
    Replies:
    1
    Views:
    269
    Allen Browne
    May 1, 2004
  2. Steve

    Function to convert decimal to hours and minutes

    Steve, Sep 8, 2004, in forum: Microsoft Access VBA Modules
    Replies:
    0
    Views:
    288
    Steve
    Sep 8, 2004
  3. Guest
    Replies:
    9
    Views:
    308
    Guest
    Mar 4, 2007
  4. Anthony

    Is it possible to track nano-seconds, or milli-seconds?

    Anthony, Nov 27, 2006, in forum: Microsoft Access VBA Modules
    Replies:
    5
    Views:
    171
  5. Anthony

    Returning Minutes and Seconds

    Anthony, Jan 22, 2007, in forum: Microsoft Access VBA Modules
    Replies:
    2
    Views:
    107
    John Vinson
    Jan 22, 2007
Loading...

Share This Page