Township Section Limit values in Textbox

Rx_

Nothing In Moderation
Local time
Today, 06:29
Joined
Oct 22, 2009
Messages
2,803
Trying to figure out during the key down event -
a.) how to also stop a leading zero (e.g. don't allow 04, but allow 4)
b.) Don't allow any combination of numbers to be outside 1 to 36
Yes, I can do this on a validate event after the fact. Just wondering if there is anything that could put this all into the KeyDown event to prevent errors in the first place.

This code works great to prevent any key entry except 0..9, Tab, and backspace
Code:
Private Sub txtSectionNumber_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode ' only accept a number 0 to 9 Backspace or Tab
            Case vbKey0, vbKey1, vbKey2, vbKey3, vbKey4, vbKey5, vbKey6, vbKey7, vbKey8, vbKey9, vbKeyBack, vbKeyTab
                ' do nothing and accept the value
            Case Else
                KeyCode = 0
        End Select
End Sub

In the US Western States, a survey township is simply a geographic reference used to define property location for deeds and grants as surveyed and platted by the General Land Office (GLO). A survey township is nominally six by six miles square. They are assigned numbers of 1 to 36.
 
Presumably you need to be able to enter values such as 10, 20 and 30; is that correct?

Also, you've neglected to allow a bunch of other keys that users frequently utilize when entering/correcting entries, such as:

Code:
vbKeyDelete, vbKeyReturn, vbKeyRight, vbKeyLeft, vbKeySpace, vbKeyEscape,  vbKeyHome, vbKeyEnd
Linq ;0)>
 
Thanks, added that as shown.
Yes, it does currently allow 10, 20, 30 - but can't check for 01 until a validate button's code is used. Was trying to keep the user from making a mistake typing and coming back.

Interesting Problem:
The keypad can not enter numbers. The regular keyboard can.
Can switch out of Access to Excel - and the keypad works perfectly.
Added a break point to the keydown event to evaluate the Keycode- sure enough the key codes for keyboard are different than the keypad.
Can't remember how much I have forgot!

vbkey5 is different than vbKeyNumpad5
Added those codes too in case someone else needs it, or in case I forget it again.

Code:
Private Sub txtSectionNumber_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode ' only accept a number 0 to 9 Backspace or Tab
            Case vbKey0, vbKey1, vbKey2, vbKey3, vbKey4, vbKey5, vbKey6, vbKey7, vbKey8, vbKey9, vbKeyBack, vbKeyTab, vbKeyDelete, _
            vbKeyReturn, vbKeyRight, vbKeyLeft, vbKeySpace, vbKeyEscape, vbKeyHome, vbKeyEnd, _
            vbKeyNumpad0, vbKeyNumpad1, vbKeyNumpad2, vbKeyNumpad3, vbKeyNumpad4, vbKeyNumpad5, vbKeyNumpad6, vbKeyNumpad7, vbKeyNumpad8, vbKeyNumpad9
                ' do nothing
            Case Else
                KeyCode = 0
        End Select
End Sub

Was trying to keep all the validation code in one spot. To prevent a 03 being entered with the key event. Zero should never be the first number entered. If => 4 is entered first - then there should never be a 2nd number.
For now, I have a Validate button to insure there are no duplicate names before saving the record. That validation code checks for the 1-36 Township requirement and sends the user back to correct it.

To be nice, the validation button looks at 01, 02, 03, ... and just fixes it for the user. Guess if the end result is the same, it doesn't matter.

Thanks for your suggestion.
 

Users who are viewing this thread

Back
Top Bottom