Bullet Proofing for Kids

  • Thread starter Thread starter Frank Wagner
  • Start date Start date
F

Frank Wagner

I have developed an application for learning the
multiplication tables using Access 2000. I am a little
worried about the kids hitting odd keys, and bringing up
messages they will not be fimiliar with. Is there a way
that I can block out all the keys except the number keys,
delete, backspace, enter and Capital T? I suppose this
could be done either for each form or all forms, but I
don't know how

Any help would be appeciated.

Thanks

Frank Wagner
 
First thing is to uncheck the box under:
Tools | Options | Startup | Special keys

Then set the KeyPreview property of your form to Yes.
Use the *form's* KeyDown property to handle all keystrokes (e.g. not
allowing Alt+F to get to the File menu). It's event procedure will look like
this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call LimitKeystroke(KeyCode, Shift)
End Sub

That calls a function that you store in a standard module, so that you can
call it from all your forms:

Function LimitKeystroke(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 96 To 111, vbKeyBack, vbKeyTab, vbKeyReturn
'Allow numeric keypad, backspace, tab, and enter.
Case Else
KeyCode = 0 'destroy every other keystroke.
End Select
End Function
 
See help for KeyPress event. Also, help for KeyPreview property.
Basically, you'd set the KeyAscii return value to 0 for any keys you want
ignored, i.e., (air code follows)

Select Case KeyAscii
Case 65 to 83, 85 to 255 'alpha keys and upper ASCII
keyAscii = 0
Case 48 to 57, 42, 43, 45, 47 'These are numeric and math
operators...do nothing
Case 13, 8, 10 'Carriage return, backspace, line feed...do nothing
Case 84 'T...do nothing
Case Else
KeyAscii = 0
End Select

You'd also need to do something in KeyDown event to trap function keys and
the like.
 
Back
Top