Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / July 2005

Tip: Looking for answers? Try searching our database.

converting decimal degrees to degrees, minutes, seconds

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DaveN - 26 Jul 2005 16:46 GMT
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
Brian - 26 Jul 2005 17:22 GMT
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

> 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
[quoted text clipped - 3 lines]
> Thanks
> Dave
DaveN - 26 Jul 2005 21:15 GMT
Thanks Brian, that works, but now how do I get it to populate the table field
"Latitude", with the converted data?

> 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
[quoted text clipped - 24 lines]
> > Thanks
> > Dave
Brian - 26 Jul 2005 22:21 GMT
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.

> Thanks Brian, that works, but now how do I get it to populate the table field
> "Latitude", with the converted data?
[quoted text clipped - 27 lines]
> > > Thanks
> > > Dave
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.