p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   Cancel a keystroke (http://p2p.wrox.com/showthread.php?t=282)

Kenny Alligood June 7th, 2003 06:43 PM

Cancel a keystroke
 
I am attempting to cancel a keystroke thru code and am not having any luck. I have a textbox on a form that I want to limit to 30 characters. I have the field in the underlying table set to a max of 30 but I want to warn the user that the maxinum has been exceeded (at 31 characters) and activate the backspace key (KeyAscii(8)). I have included an IF..THEN option in mt textbox_Change event but I am unable to get the backspace function working. Any ideas or suggestions are greatly appreciated.

Thanx in Advance


Kenny Alligood

Steven June 9th, 2003 12:46 AM

Try putting some code in the textbox's Key Up event.

Something along the lines of this should work:
Code:

Private Sub Text0_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text0.Text) > 30 Then SendKeys Chr(8)
End Sub


HTH

Steven

I am a loud man with a very large hat. This means I am in charge.

SerranoG June 9th, 2003 11:37 AM

Quote:

quote:Originally posted by Kenny Alligood
 I am attempting to cancel a keystroke thru code and am not having any luck. I have a textbox on a form that I want to limit to 30 characters. I have the field in the underlying table set to a max of 30 but I want to warn the user that the maxinum has been exceeded (at 31 characters) and activate the backspace key (KeyAscii(8)).
 I don't understand why you need to code this. If the field is limited to 30 characters then when the user tries to type the 31st character, Access will just not type it. The user then knows that the limit has been reached. Because the 31st character will not be even allowed to be typed, there is no need to activate a backspace. Doing so will erase the 30th character. You don't want that.

Unless I misunderstand your intention it sounds like you're creating more work for yourself. Let Access function by default in this case.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division

Kenny Alligood June 12th, 2003 09:57 AM

Your reply worked the charm I needed - thanx for the advice.

Kenny Alligood

Kenny Alligood June 12th, 2003 10:02 AM

Quote:

quote:Originally posted by SerranoG
 
Quote:

quote:Originally posted by Kenny Alligood
Quote:

 I am attempting to cancel a keystroke thru code and am not having any luck. I have a textbox on a form that I want to limit to 30 characters. I have the field in the underlying table set to a max of 30 but I want to warn the user that the maxinum has been exceeded (at 31 characters) and activate the backspace key (KeyAscii(8)).
 I don't understand why you need to code this. If the field is limited to 30 characters then when the user tries to type the 31st character, Access will just not type it. The user then knows that the limit has been reached. Because the 31st character will not be even allowed to be typed, there is no need to activate a backspace. Doing so will erase the 30th character. You don't want that.

Unless I misunderstand your intention it sounds like you're creating more work for yourself. Let Access function by default in this case.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
The reason that I wanted to include code was that Access does indeed limit the fields maximum property but it does not let the user know that it is limited. I tested that to be certain but that is the case. When I entered more than 30 characters the textbox processed the text up to the 30th character and removed the rest - never letting the user know this. If the user has no way to see the underlying table (which mine do not) then they would never know that a portion of their data was deleted due to size limitations. With the code I can include a MsgBox and backspace key to alert the user accordingly. Nevertheless, I do appreciate your reply it gave me the opportunity to test something that I wasn't certain about to begin with. As such, I have always wanted to include code to control my environment as opposed to depending on the application.

Kenny Alligood


All times are GMT -4. The time now is 02:59 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.