PC Review


Reply
Thread Tools Rate Thread

Activating a command button with a single key stroke

 
 
Bishop
Guest
Posts: n/a
 
      3rd Jun 2009
Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      3rd Jun 2009
Use the keydown event of the command button. or the userform..

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 65 Then MsgBox "Run"
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

> Is there a way to activate a command button by simply pressing a single
> letter on the keyboard? For example, say I have a button that says "Add A
> Title". When I press the A key I want the button to activate and process
> whatever code is attached to it.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Jun 2009
You could use the Accelerator property, but then use alt-A to run the _click
event for that command button. (Include the A somewhere in the caption!)

Kind of like what you see in the xl2003 menu--where the F in File is underlined,
E in Edit, etc.

Bishop wrote:
>
> Is there a way to activate a command button by simply pressing a single
> letter on the keyboard? For example, say I have a button that says "Add A
> Title". When I press the A key I want the button to activate and process
> whatever code is attached to it.


--

Dave Peterson
 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      3rd Jun 2009
read help on
APPLICATION.ONKEY key, procedure

when this is run
APPLICATION.ONKEY "Q", "doThis"

whenever the user presses the Q key, the sub called doThis is run


"Bishop" <(E-Mail Removed)> wrote in message
news084D17B-5866-4120-BB25-(E-Mail Removed)...
> Is there a way to activate a command button by simply pressing a single
> letter on the keyboard? For example, say I have a button that says "Add A
> Title". When I press the A key I want the button to activate and process
> whatever code is attached to it.


 
Reply With Quote
 
Bishop
Guest
Posts: n/a
 
      3rd Jun 2009
I have the following code:

Private Sub AddButton_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

Dim A As Integer

If KeyCode = A Then
AddTitle.Show
End If

End Sub

but it doesn't work. What am I doing wrong?

"Jacob Skaria" wrote:

> Use the keydown event of the command button. or the userform..
>
> Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
> ByVal Shift As Integer)
> If KeyCode = 65 Then MsgBox "Run"
> End Sub
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Bishop" wrote:
>
> > Is there a way to activate a command button by simply pressing a single
> > letter on the keyboard? For example, say I have a button that says "Add A
> > Title". When I press the A key I want the button to activate and process
> > whatever code is attached to it.

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      3rd Jun 2009
Its returning the character code..65 for A and so on..However if you are
unfamilar use the below code....

Dim A As Integer

If Chr(KeyCode) = "A" Then
AddTitle.Show
End If

If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

> I have the following code:
>
> Private Sub AddButton_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
> ByVal Shift As Integer)
>
> Dim A As Integer
>
> If KeyCode = A Then
> AddTitle.Show
> End If
>
> End Sub
>
> but it doesn't work. What am I doing wrong?
>
> "Jacob Skaria" wrote:
>
> > Use the keydown event of the command button. or the userform..
> >
> > Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
> > ByVal Shift As Integer)
> > If KeyCode = 65 Then MsgBox "Run"
> > End Sub
> > --
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "Bishop" wrote:
> >
> > > Is there a way to activate a command button by simply pressing a single
> > > letter on the keyboard? For example, say I have a button that says "Add A
> > > Title". When I press the A key I want the button to activate and process
> > > whatever code is attached to it.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activating a Command Button on a Form Slej Microsoft Access Forms 2 15th Jan 2010 02:32 PM
Command button - check listbox contents before activating? Roger on Excel Microsoft Excel Programming 3 4th Dec 2009 09:00 AM
activating a command button chuck Microsoft Excel Misc 1 10th Sep 2009 03:12 AM
command button wizard not activating Debbie S. Microsoft Access 3 28th Dec 2007 11:31 PM
Activating a command button after a certain date passes. =?Utf-8?B?Q2hyaXMgRS4=?= Microsoft Access Form Coding 3 31st Oct 2006 02:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:43 PM.