Is it possible to narrow an input mask to 4 letter of the alphabete? (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:54
Joined
May 21, 2018
Messages
8,463
The code is in a module called mdlLatLong. Understand a module here:
https://www.fontstuff.com/vba/vbatut04.htm




I replaced your GetStringLatLong with GetStringLatitude, which is the field I'm trying to autopopulate
Functions are reusable blocks of code. You send things in and get something back. This same function could be used for either lat or long. No need to rename.

June7, for the moment, I working with degrees, minutes, seconds because the software we are going to use read the latitude that way.
I think you are still missing the point. How you store the data does not dictate how you display the data or pass it on. If you store it +- decimal degrees you can easily display or share it as a string of degree minutes seconds. I have shown multiple ways to do that. If it is stored as a decimal you can easily convert it into many different forms. If stored as a string it get s more complicated.
 

Attachments

  • Module.jpg
    Module.jpg
    75 KB · Views: 197

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:54
Joined
May 21, 2018
Messages
8,463
Also for your degrees if they select a cardinal of N S then you need to verify the range is between 0 to 90 and if they select E, S then it needs to verify 0-180. Not sure if you are using the same unbound controls for both. So you may want to make all the deg, min, sec to be hidden first. Make the user first select E,S,W,N before unhiding the other controls. Then you can use the value in there to verify the value in the before update of the Deg textbox. May have to also do code in the after update of the cardinal to go back and reverify the degrees.
 

Mat1994

Registered User.
Local time
Today, 14:54
Joined
Nov 29, 2018
Messages
94
Great! It's working now. Your GetStringLatLong was the missing piece of the puzzle.
I now have to repeat this method a few time, for example the longitude.

No, I've notice our validation controls are not the same but both our methos work.

Thank you very much, I appreciate it a lot,
Mat
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:54
Joined
May 21, 2018
Messages
8,463
Let me send another demo using a pop up to reuse the same code in many places.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:54
Joined
May 21, 2018
Messages
8,463
This demo use a pop and and sets the validation for lat long. It is used on both the lat and long fields. I modified the code to save the +- decimal degrees.
 

Attachments

  • DemoLatLong 3.accdb
    588 KB · Views: 67

Mat1994

Registered User.
Local time
Today, 14:54
Joined
Nov 29, 2018
Messages
94
Thank you,

I don't know if my colleagues want a conversion option in the interface. I'll need to discuss this with them.

Mat
 

Mat1994

Registered User.
Local time
Today, 14:54
Joined
Nov 29, 2018
Messages
94
Hi MajP, sorry to come back to this post.
A colleagues told me he would like to have the seconds with 2 decimals number.

In the property sheet of the latitude_seconds, I changed the decimal places to 2. That works ok.
That the problem is : when the latitude uploads itselfs it rounds the seconds

For example when I input :
Lat_degrees : 12
Lat_minutes: 12
Lat_seconds: 12.62
Lat_cardinal N

Then latitude populates itself to : 12ø12'13''N

Do you know how I could get the latitude : 12ø12'12.62''N ?

Thank you,
Mat
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:54
Joined
May 21, 2018
Messages
8,463
Likely have to change it in several places.
Not sure what parts of the code you are using.
Need to change long to double in several places
Code:
Public Function GetDecimalDegrees(degrees As Long, minutes As Long, seconds As [B][COLOR="Red"]Double[/COLOR][/B]) As Double
   GetDecimalDegrees = degrees + minutes / 60 + seconds / 3600
End Function

Public Function GetStrLatLongFromDec(ByVal DecimalDegrees As Variant, Cardinal As Variant) As String
  Dim deg As Long
  Dim min As Long
  Dim sec As [COLOR="Red"][B]Double[/B][/COLOR]
  If Not IsNull(DecimalDegrees) And Not IsNull(Cardinal) Then
    DecimalDegrees = Abs(DecimalDegrees)
    deg = Int(DecimalDegrees)
    min = Int((DecimalDegrees - deg) * 60)
    sec = Format((DecimalDegrees - deg - min / 60) * 3600, "##.##")
    GetStrLatLongFromDec = deg & Chr(248) & " " & min & "' " & sec & "'' " & Cardinal
  End If
End Function
Public Function GetStringLatLong(degrees As Long, minutes As Long, seconds As [COLOR="red"]Double[/COLOR], Direction As String) As String
  GetStringLatLong = degrees & Chr(248) & " " & minutes & "' " & seconds & "'' " & Direction
End Function


Public Property Get DecimalDegrees() As Double
   Dim deg As Long
   Dim min As Long
   Dim sec As [COLOR="red"]Double[/COLOR]
   deg = Nz(Me.txtDeg)
   min = Nz(Me.txtMin)
   sec = Nz(Me.txtSec)
   DecimalDegrees = deg + min / 60 + sec / 3600
   If Me.cmboCardinal = "S" Or Me.cmboCardinal = "W" Then DecimalDegrees = -1 * DecimalDegrees
  
End Property
 

Mat1994

Registered User.
Local time
Today, 14:54
Joined
Nov 29, 2018
Messages
94
Perfect, changing it to "double" works.
I've also tried setting the input mask of lat_seconds to a 4 digits (2 integer number and 2 decimal number). When I set the input mask to 99,99 or 99.99 I get a error message saying I don't respect my validation rule. Where the latitude seconds must be between 0 and 59 seconds.
I'm guessing the "," or "." isn't used properly. Do you know how I can set my input mask?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:54
Joined
May 21, 2018
Messages
8,463
When you create an input mask there are several parameters. The second one tells it if it should save the literal characters or not.
99.99;;#
will not save the "." So the value 45.45 is saved as 4545
99.99;0;#
Second argument says save the ".". So 45.45 is saved as 45.45

The second part is optional and refers to the embedded mask characters and how they are stored within the field. If the second part is set to 0, the characters are stored with the data, and if it is set to 1, the characters are only displayed and not stored. Setting the second part to 1 can save database storage space.
However, this parameter is optional and I think the default is 1 (strangely).
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:54
Joined
May 21, 2018
Messages
8,463
What code did you decide to use? Are you using the pop up? Are you saving just the string or saving the decimaldegrees as well? Looking at the example, I would think if you are using the pop up then you may want another feature. If there is a value in the field already then the pop up should default to the stored value. If you want that I can add.
 

Mat1994

Registered User.
Local time
Today, 14:54
Joined
Nov 29, 2018
Messages
94
I'm using :

Code:
Public Function GetStringLatLong(degrees As Long, minutes As Long, seconds As Double, Direction As String) As String
' function that defines the formats
  GetStringLatLong = degrees & Chr(248) & " " & minutes & "' " & seconds & "'' " & Direction

End Function

Public Sub FillLatitude() 'fills in the latitude automatically

'case 1 : fills in the latitude
  If (IsNumeric(Me.LAT_degrees) And IsNumeric(Me.LAT_Minutes) And IsNumeric(Me.LAT_Seconds) And Not IsNull(Me.cbo_Lat_Cardinal)) Then
    Me.Latitude = GetStringLatLong(Me.LAT_degrees, Me.LAT_Minutes, Me.LAT_Seconds, Me.cbo_Lat_Cardinal)
    Me.Repaint
    Me.Recalc
   
  End If
End Sub

Private Sub LAT_degrees_AfterUpdate()
    FillLatitude
End Sub

Private Sub LAT_Minutes_AfterUpdate()
    FillLatitude
End Sub

Private Sub LAT_Seconds_AfterUpdate()
    FillLatitude
End Sub

Private Sub cbo_Lat_Cardinal_AfterUpdate()
    FillLatitude
End Sub

I'm using the fill function. The code you've given me works fine.
The degrees, minutes, secondes and cardinal fill in the latitude field. Only the latitude is a saved and stored value. I'll have to convert the latitude in decimal but I'm not working on it at the moment. I need to tri it myself, and if I have problems I'll come back here.
Mat
 

Users who are viewing this thread

Top Bottom