Access 2007,reports,VBA


J

Jeff Joyner

I have a field in my report which contains GPS information. I am trying toget the value from this field and use it in VBA code to convert it to decimal notation. I am trying to do this in an unbound text box so I would have the GPS value and it's decimal value side by side in my report. I came across some VBA code that does the conversion, but for the life of me I can't figure out how to get the GPS value from my field (NLatitude) into the VBA code as a variable. Obviously, I don't understand VBA that well and needhelp.

Here is the code I am trying to use:

Function Convert_Decimal(Degree_Deg As String) As Double
' Declare the variables to be double precision floating-point.
Dim degrees As Double
Dim minutes As Double
Dim seconds As Double
' Set degree to value before "°" of Argument Passed.
degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "°") - 1))
' Set minutes to the value between the "°" and the "'"
' of the text string for the variable Degree_Deg divided by
' 60. The Val function converts the text string to a number.
minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "°") + 2, _
InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, _
"°") - 2)) / 60
' Set seconds to the number to the right of "'" that is
' converted to a value and then divided by 3600.
seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _
2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) _
/ 3600
Convert_Decimal = degrees + minutes + seconds

I am thinking that 'Degree_deg' is the argument I need to alter, but I don't know how to do it.
 
Ad

Advertisements

A

Access Developer

As long as you are not trying to accumulate a sum/total, you can put code in
the Format event of the Report Section (probably Detail) in which the two
Controls reside. How you address the Control depends on where the code is
located (in the Detail Section of the Report, or in a Subreport, etc.).

--
Larry Linson
Microsoft Office Access MVP
Co-Author, Microsoft Access Small Business Solutions, Wiley 2010

I have a field in my report which contains GPS information. I am trying to
get the value from this field and use it in VBA code to convert it to
decimal notation. I am trying to do this in an unbound text box so I would
have the GPS value and it's decimal value side by side in my report. I came
across some VBA code that does the conversion, but for the life of me I
can't figure out how to get the GPS value from my field (NLatitude) into the
VBA code as a variable. Obviously, I don't understand VBA that well and
need help.

Here is the code I am trying to use:

Function Convert_Decimal(Degree_Deg As String) As Double
' Declare the variables to be double precision floating-point.
Dim degrees As Double
Dim minutes As Double
Dim seconds As Double
' Set degree to value before "°" of Argument Passed.
degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "°") - 1))
' Set minutes to the value between the "°" and the "'"
' of the text string for the variable Degree_Deg divided by
' 60. The Val function converts the text string to a number.
minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "°") + 2, _
InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, _
"°") - 2)) / 60
' Set seconds to the number to the right of "'" that is
' converted to a value and then divided by 3600.
seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _
2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) _
/ 3600
Convert_Decimal = degrees + minutes + seconds

I am thinking that 'Degree_deg' is the argument I need to alter, but I don't
know how to do it.
 
Ad

Advertisements

N

Norman Peelman

I have a field in my report which contains GPS information. I am trying to get the value from this field and use it in VBA code to convert it to decimal notation. I am trying to do this in an unbound text box so I would have the GPS value and it's decimal value side by side in my report. I came across some VBA code that does the conversion, but for the life of me I can't figure out how to get the GPS value from my field (NLatitude) into the VBA code as a variable. Obviously, I don't understand VBA that well and need help.

Here is the code I am trying to use:

Function Convert_Decimal(Degree_Deg As String) As Double
' Declare the variables to be double precision floating-point.
Dim degrees As Double
Dim minutes As Double
Dim seconds As Double
' Set degree to value before "°" of Argument Passed.
degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "°") - 1))
' Set minutes to the value between the "°" and the "'"
' of the text string for the variable Degree_Deg divided by
' 60. The Val function converts the text string to a number.
minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "°") + 2, _
InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, _
"°") - 2)) / 60
' Set seconds to the number to the right of "'" that is
' converted to a value and then divided by 3600.
seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _
2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) _
/ 3600
Convert_Decimal = degrees + minutes + seconds
End Function

I am thinking that 'Degree_deg' is the argument I need to alter, but I don't know how to do it.

You would 'pass' your 'field' to this function and it will return to you
a value, so:

' your new variable
Dim NLatitude_Decimal As Double
'...
' use the path to your textbox - ie: Me!NLatitude.Value or
Forms!formname!NLatitude.Value
NLatitude_Decimal = Convert_Decimal(Me!NLatitude.Value)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top