Hotkey - SPACE BAR

Posted on 2002-04-25
Last Modified: 2012-06-27
I use KeyPreview = True for form

Then have:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeySpace Then
 etc etc

Problem - if i run the program it performs the keydown event ok but also any command button that has the focus at the time - no good

How to simply get the SPACE BAR to perform something on its own ?
Question by:clapper100497
  • 2
  • 2

Accepted Solution

DrDelphi earned 100 total points
ID: 6970326
Try this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 32 Then
   MsgBox "Space key pressed"
   KeyCode = 0
End If

Good luck!!

Author Comment

ID: 6970333
KeyCode = 0 did the trick !
Well done and thanks !!!!

Author Comment

ID: 6970335
Thanks for such a simple solution
Appreciated !!!

Expert Comment

ID: 6970342


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 78
MsgBox 2 59
Copy a row 12 64
VBA- How to change font, color and format in outlook e-mail sent from Access 2 68
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question