Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

allow only letter in textbox 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
429
IT
I need to force the user to insert only letter in textbox and max lenght 2 cahracter...
 
one way might be to use the masked edit control, with the mask set to "AA" and the prompt set to " "

Another way is to throw away characters you do not want inserted during the textboxes keypress event
 
Strongm...

my study, wath you think about:

Code:
Private Sub TPR_KeyPress(KeyAscii As Integer)

    KeyAscii = Asc(UCase(Chr(KeyAscii)))

    Select Case Chr(KeyAscii)
    Case 0 To 9
        KeyAscii = 0
    End Select

End Sub
 
Bit convoluted (I'd use [tt]Case 48 to 57[/tt] and avoid any preprocessing of KeyAscii, since KeyAscii gets passed on to the default handler for the control), but essentially yes. I'd also put in a string length check here as well to meet your "max lenght 2 cahracter" requirement
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top