UserForm, CommandButton, Accelerator Key 
Author Message
 UserForm, CommandButton, Accelerator Key

I am trying to create a UserForm with multiple click buttons with
accelerator keys. I created the first button, putting the accelerator
key in the Properties for the button. This seemed to work. However, when

I added two more buttons, it now only works if I click the buttons. I
want to be able to use the accelerator keys. Does someone have some
macro code events for a multiple button userform they could send me?
Here's what I have at the moment (and I have Unload now, but before I
was using the .Hide property, but thought that maybe the keypresses
weren't working because I was only hiding the dialog rather than
unloading).

Thx.

P.S. I posted this a few days ago, but never got a reply, and don't see
the original message on the board anywhere, so I re-posted it.

-Rich Belthoff

Private Sub TrackAllOn_Click()
With activedocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
Unload CtrlOO_Dlg
End Sub

Private Sub TrackAllOn_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

With activedocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
Unload CtrlOO_Dlg
End Sub

Private Sub TrackDisplayOff_Click()
With activedocument
.TrackRevisions = True
.PrintRevisions = False
.ShowRevisions = False
End With
Unload CtrlOO_Dlg
End Sub

Private Sub TrackDisplayOff_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
With activedocument
.TrackRevisions = True
.PrintRevisions = False
.ShowRevisions = False
End With
Unload CtrlOO_Dlg
End Sub

Private Sub TrackOptionsAllOff_Click()
With activedocument
.TrackRevisions = False
.PrintRevisions = False
.ShowRevisions = False
End With
Unload CtrlOO_Dlg
End Sub

Private Sub TrackOptionsAllOff_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
With activedocument
.TrackRevisions = False
.PrintRevisions = False
.ShowRevisions = False
End With
Unload CtrlOO_Dlg
End Sub



Fri, 07 Feb 2003 03:00:00 GMT  
 UserForm, CommandButton, Accelerator Key

You should be able to assign an accelerator keys to most controls on a form
but they have to be unique.

Mark Baird

Quote:
> I am trying to create a UserForm with multiple click buttons with
> accelerator keys. I created the first button, putting the accelerator
> key in the Properties for the button. This seemed to work. However, when

> I added two more buttons, it now only works if I click the buttons. I
> want to be able to use the accelerator keys. Does someone have some
> macro code events for a multiple button userform they could send me?
> Here's what I have at the moment (and I have Unload now, but before I
> was using the .Hide property, but thought that maybe the keypresses
> weren't working because I was only hiding the dialog rather than
> unloading).

> Thx.

> P.S. I posted this a few days ago, but never got a reply, and don't see
> the original message on the board anywhere, so I re-posted it.

> -Rich Belthoff

> Private Sub TrackAllOn_Click()
> With activedocument
> .TrackRevisions = True
> .PrintRevisions = True
> .ShowRevisions = True
> End With
> Unload CtrlOO_Dlg
> End Sub

> Private Sub TrackAllOn_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

> With activedocument
> .TrackRevisions = True
> .PrintRevisions = True
> .ShowRevisions = True
> End With
> Unload CtrlOO_Dlg
> End Sub

> Private Sub TrackDisplayOff_Click()
> With activedocument
> .TrackRevisions = True
> .PrintRevisions = False
> .ShowRevisions = False
> End With
> Unload CtrlOO_Dlg
> End Sub

> Private Sub TrackDisplayOff_KeyPress(ByVal KeyAscii As
> MSForms.ReturnInteger)
> With activedocument
> .TrackRevisions = True
> .PrintRevisions = False
> .ShowRevisions = False
> End With
> Unload CtrlOO_Dlg
> End Sub

> Private Sub TrackOptionsAllOff_Click()
> With activedocument
> .TrackRevisions = False
> .PrintRevisions = False
> .ShowRevisions = False
> End With
> Unload CtrlOO_Dlg
> End Sub

> Private Sub TrackOptionsAllOff_KeyPress(ByVal KeyAscii As
> MSForms.ReturnInteger)
> With activedocument
> .TrackRevisions = False
> .PrintRevisions = False
> .ShowRevisions = False
> End With
> Unload CtrlOO_Dlg
> End Sub



Sat, 08 Feb 2003 13:39:13 GMT  
 UserForm, CommandButton, Accelerator Key
It does not need to be a function of your code, but the tab-index /
tab-order properties for each  tool and label.

Look for Help under "Accelerator", which seems quite clear, or ask again and
I will post an example

Cliff Forrest

--

.



Sun, 09 Feb 2003 03:00:00 GMT  
 UserForm, CommandButton, Accelerator Key
Thanks. However, I don't think Help under "Accelerator" is that clear for what I
want to do, or at least I don't understand what it says. I've assigned unique
accelerators in the Properties for each of the three command buttons. The
problem is that no matter which key I press when the UserForm is displayed, only
the first set of commands gets processed under Private Sub
TrackAllOn_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) rather than the
appropriate set of commands for the key pressed (notice in my original message
that I have three KeyPress events in the code - the other two are never executed
- when I run it with F8 to step through the process, after I press a key, no
matter which key, TrackAllOn_KeyPress is run). How do I get the macro to go to
the other KeyPress events?? I suspect that I'm just going about this the wrong
way. I would have thought just sticking in the Sub ????_KeyPress events would
work properly, but apprently not. The keypresses aren't filtered to the
appropriate code.

Thanks for you help.

-Rich.

Quote:

> It does not need to be a function of your code, but the tab-index /
> tab-order properties for each  tool and label.

> Look for Help under "Accelerator", which seems quite clear, or ask again and
> I will post an example

> Cliff Forrest

> --

> .



Fri, 14 Feb 2003 03:00:00 GMT  
 UserForm, CommandButton, Accelerator Key

Hi Richard,

Quote:
> I am trying to create a UserForm with multiple click buttons with
> accelerator keys. I created the first button, putting the accelerator
> key in the Properties for the button. This seemed to work. However, when

> I added two more buttons, it now only works if I click the buttons.

Basically, Accelerator keys' functionality is to simply let you move the
focus to the control (button). Once you get there, you'd need to press
ENTER to make the "click" event behind the button function.

There really isn't any way I know of to assign "shortcut" keys to a
UserForm, so that pressing a particular key combination will run a macro
(unless the focus is in a control that accepts and works with Keypress -
but you can't to that for an entire form).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Sun, 23 Feb 2003 22:31:45 GMT  
 UserForm, CommandButton, Accelerator Key

having your code executed by the GotFocus event for the
command button?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)



Mon, 24 Feb 2003 00:40:02 GMT  
 UserForm, CommandButton, Accelerator Key
Thanks for the replies. I'll check into the GotFocus command. In your
one message, you say you don't know of a way to trigger the macro when I
press a key while a UserForm is displayed. However, from the beginning,
whenever I pressed one of my accelerator keys, the UserForm disappeared
and macro code ran. It just wasn't the proper code for the assigned
accelerator key. I can't send you the UserForm code without sending you
my normal.dot, but it is just a plain old UserForm with only three
CommandButtons (no OK or Cancel). Here is the code I now use to trigger
what I want.

Private Sub TrackAllOn_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii = 97 Then       'ASCII 97 = "a"
        With activedocument
            .TrackRevisions = True
            .PrintRevisions = True
            .ShowRevisions = True
        End With
    End If
    If KeyAscii = 115 Then      'ASCII 115 = "s"
        With activedocument
            .TrackRevisions = True
            .PrintRevisions = False
            .ShowRevisions = False
        End With
    End If
    If KeyAscii = 102 Then      'ASCII 102 = "f"
        With activedocument
            .TrackRevisions = False
            .PrintRevisions = False
            .ShowRevisions = False
        End With
    End If
    Unload CtrlOO_Dlg
End Sub

Private Sub TrackAllOn_Click()
    With activedocument
        .TrackRevisions = True
        .PrintRevisions = True
        .ShowRevisions = True
    End With
    Unload CtrlOO_Dlg
End Sub

Private Sub TrackDisplayOff_Click()
    With activedocument
        .TrackRevisions = True
        .PrintRevisions = False
        .ShowRevisions = False
    End With
    Unload CtrlOO_Dlg
End Sub

Private Sub TrackOptionsAllOff_Click()
    With activedocument
        .TrackRevisions = False
        .PrintRevisions = False
        .ShowRevisions = False
    End With
    Unload CtrlOO_Dlg
End Sub

Note the first grouping of code. That actually executes depending upon
the key pressed with the UserForm displayed. Previously, I had three Sub
"KeyPress" groupings before, but only the first ran (i.e., the three
sets of options each had its own Sub "KeyPress", but only the first
ran). I then combined them, figured out the ASCII code for the key being
pressed, and created the IF statements. This works, but I keep thinking
that I'm going about this the wrong way. I thought accelerator keys
triggered the command button. I didn't realize they were only designed
to change focus. Well, anyway, I guess if my way works, I should stick
with it. However, if you have any more elegant ideas, please let me
know.

Thanks.

-Rich.

Quote:


> having your code executed by the GotFocus event for the
> command button?

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://go.compuserve.com/MSOfficeForum

> This reply is posted in the Newsgroup; please post any
> follow question or reply in the newsgroup and not by e-mail
> :-)



Sat, 08 Mar 2003 03:00:00 GMT  
 UserForm, CommandButton, Accelerator Key
Hi Richard,

Quote:
> I thought accelerator keys
> triggered the command button. I didn't realize they were only designed
> to change focus.

I *think* if your accelerator key is the DEFAULT command button on the
form (such as O for OK), it will actually trigger the button.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)



Fri, 21 Mar 2003 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Creating new document based on template using commandbutton on userform

2. Word 2000, CommandBars and Accelerator Keys.

3. Accelerator Key Display in Custom Menu

4. Accelerator key problem

5. Accelerator key takes 2 tries to open combobox

6. User Forms, Command Buttons, Accelerator Keys

7. Accelerator keys in VB.NET

8. Accelerator keys won't display on form load

9. Accelerator keys on toolbar?

10. Accelerator Keys not recognized

11. Accelerator Keys in SSTab control

12. Accelerator Keys in VBS?

 

 
Powered by phpBB® Forum Software