Results 1 to 6 of 6
  1. #1
    Playerpawn is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    11

    OnKeyPress event - validation


    I've read examples I found on Google, but none work.

    I would like to put a public function into the OnKeyPress event of many unbound textboxes on my form that would only allow the user to enter approved characters (alphanumeric).

    Any suggestions?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Well, generally speaking the code behind the keypress event would examine KeyAscii, and conditionally return something different. If you wanted to use a function for that, it would have to accept KeyAscii as an input parameter, and return one back. Behind each textbox's keypress event, you'd call that function and use the return, like

    KeyAscii = FunctionName(KeyAscii)

    Your function would examine the input, and either return it back or whatever you want substituted (probably 0).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Playerpawn is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    11
    I put "KeyAscii = KeyValid(KeyAscii)" into my event and it says it doesn't know what it is. "Microsoft Access cannot find the object".

    Any ideas?

    I under the idea of making a function to return a modified KeyAscii number... but calling it from the textbox control's onkeypress event isn't working thus far.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    That would have to be in the VBA code editor, not right in the properties window, which is where it sounds like you have it.

    http://www.baldyweb.com/FirstVBA.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Playerpawn is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    11
    So I'll have to have a controlname_keypress() function for every control I want to use this?

    I have a LOT of controls.

    Is there any way all of the controls can use one keypress function?

    Thanks for your assistance.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You'd have one function, called from multiple controls. Each control would have that single line of code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. List Box Not Recognize OnKeyPress ENTER
    By Rawb in forum Programming
    Replies: 1
    Last Post: 02-14-2011, 08:04 AM
  2. Validation Rules
    By esglover in forum Database Design
    Replies: 1
    Last Post: 07-23-2010, 08:02 PM
  3. Validation Question
    By ksmithson in forum Forms
    Replies: 1
    Last Post: 07-15-2010, 03:02 PM
  4. Replies: 21
    Last Post: 06-03-2009, 05:54 PM
  5. Validation problems...
    By dbDamo in forum Forms
    Replies: 1
    Last Post: 05-15-2009, 12:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums