Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2003, 06:43 PM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
__________________
Kenny Alligood
 
Old June 9th, 2003, 12:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old June 9th, 2003, 11:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old June 12th, 2003, 09:57 AM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Kenny Alligood
 
Old June 12th, 2003, 10:02 AM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
cancel appointment jeanhl BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 March 25th, 2008 03:55 AM
How can I cancel deleting ? ALGNET ADO.NET 1 March 22nd, 2006 01:55 PM
how about cancel a process kevsboy Beginning VB 6 0 February 12th, 2006 11:03 PM
Capture Keystroke in a text box xgbnow Visual C++ 0 October 1st, 2003 11:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.