Spacebar Triggers OnClick Event

  • Thread starter Thread starter JamesJ
  • Start date Start date
J

JamesJ

When I hit the spacebar and a command button has
the focus it triggers the OnClick of the button. Is this
normal? How can I prevent this from occurring?

Thanks,
James
 
Didn't realize it myself, but yes, apparently it is normal! To prevent this
you need to capture the Spacebar being pressed and reassign it. You could do
this on a form wide basis, but then you wouldn't be able to use the spacebar
when entering text, so I think you're stuck with doing this for each command
button you want to "protect."

Private Sub YourButton_KeyDown(KeyCode As Integer, Shift As Integer)
If vbKeySpace Then
KeyCode = 0
End If
End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
All you need to do is to open the property sheet, go to the Other Tab and
set the Tab Stop property to No. The way, the only way a command button will
ever get focus is when you click on it with the mouse, or use mnemonics (Alt
+ Keystroke for underlined characters)
 
Just found something else out. There's no other control on the
form that can get the focus.

James
 
No other controls can recieve the focus on this form so
trapping the spacebar on a formwide basis worked fine.
Sorry 'bout the other threads.

James
 
Back
Top