Spacebar Triggers OnClick Event

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
 
M

missinglinq via AccessMonster.com

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
 
A

Arvin Meyer [MVP]

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)
 
J

JamesJ

Just found something else out. There's no other control on the
form that can get the focus.

James
 
J

JamesJ

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top