|
-
Sep 14th, 2005, 02:54 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Trouble with the Keypress event of a textbox
I have the following code in the Keypress event of a textbox.
VB Code:
If Val(txtRooms) = 0 Then
MsgBox "Zero is an invalid entry", vbInformation, "Invalid Entry"
txtRooms = vbNullString
txtRooms.SetFocus
Exit Sub
Else
Call cmdSubmitChange_Click
End If
It works but it doesn't reset the value in the textbox. For example, if the user enters "0", it fires the msgbox saying it's an invalid entry, and then it pops the zero into the textbox. How do I tell it NOT to display the value just entered?
-
Sep 14th, 2005, 03:00 PM
#2
Re: Trouble with the Keypress event of a textbox
u need to intercept & change the KeyAscii
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 48 Then '48 = 0
MsgBox "Zero is an invalid entry", vbInformation, "Invalid Entry"
KeyAscii = 0
txtRooms.SetFocus
Exit Sub
Else
Call cmdSubmitChange_Click
End If
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 14th, 2005, 03:02 PM
#3
Re: Trouble with the Keypress event of a textbox
Try this :
VB Code:
If Val(txtRooms) = 0 Then
MsgBox "Zero is an invalid entry", vbInformation, "Invalid Entry"
txtRooms = vbNullString
txtRooms.SetFocus
[b]KeyAscii = 0[/b]
Exit Sub
Else
Call cmdSubmitChange_Click
End If
Not sure it'll work though...
Has someone helped you? Then you can Rate their helpful post. 
-
Sep 15th, 2005, 08:11 AM
#4
Thread Starter
Fanatic Member
Re: Trouble with the Keypress event of a textbox
Thanks for the help guys.
-
Sep 15th, 2005, 08:14 AM
#5
Re: Trouble with the Keypress event of a textbox
Well, then move the reset line above the messagebox line. That'll take care of that sucker right quick!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|