Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cancel a Shortcut menu in a MouseUp (or Down) event

52 views
Skip to first unread message

Dev Ashish

unread,
Mar 6, 1999, 3:00:00 AM3/6/99
to
Hi Alan,

If I can understand the problem correctly, won't something like this work?

Private Sub Command0_Click()
Me.ShortcutMenu = True
End Sub

Private Sub Command1_Click()
Me.ShortcutMenu = False
End Sub

HTH
-- Dev

Alan Carpenter wrote in message <36E11883...@ihug.co.nz>...
:Very Public Sub cmdExample_MouseUp(Button As Integer, Shift As Integer,
:X As Single, Y As Single)
:On Error GoTo Err_cmdExample_MouseUp
:
:If Button = acLeftButton Then
: DoThings (withStuff)
:ElseIf Button = acRightButton Then
: DoDifferentThings (withStuff)
:
: Rem Access 2.0 and Access 97
: Set X =
:Do_Something_To_Prevent_RightClick_Shortcut_Menu_From_Showing
:
: If X = RTFM Then
: Answer = "I spent some time looking, but I didn't find what I
:needed"
: ElseIf X = "It's in the Help File" Then
: Answer = "The Help example makes no mention of the Shortcut
:Menu"
: ElseIf X = DoCmd.CancelEvent Then
: Answer = "It didn't work for me"
: ElseIf X = "Use Sendkeys '(ESC)'" Then
: Answer = "Not bloody likely"
: ElseIf X = "Use the Form's ShortcutMenu Property" Then
: Answer = "Sorry, I tried that, but it doesn't feel right"
: Else
: Answer = "Curse this senile decay of my mind"
: End If
:End If
:Exit_cmdExample_MouseUp:
: Exit Sub
:Err_cmdExample_MouseUp:
: MsgBox Err.Description
: Resume Exit_cmdExample_MouseUp
:End Sub
:
:
: Or to put it another way, if I were to put a button on a form, with the
:button's caption reading something like, "Left click for tea, Right
:click for coffee," I'm sure there's a nice easy, simple, probably
:single-word command to cancel the Rightclick Shortcut Menu.
:
: Please tell me this word of power for which I have sought these many
:days in the wilderness of Access documentation, that I might complete my
:long misson and rest my weary head as I recite those most inaccurate of
:all Mantras, "At last my Access Database is complete."
:
:Cheers all
:
:Alan Carpenter
:ala...@ihug.co.nz
:

Alan Carpenter

unread,
Mar 7, 1999, 3:00:00 AM3/7/99
to

Alan Carpenter

unread,
Mar 7, 1999, 3:00:00 AM3/7/99
to
Hi Dev

Sorry for the rather rambling description.

Yes, two buttons to turn off or on shortcut menus will work perfectly. I
have no problem with that.
However, try this rather artifical example.

A single button with the rather long caption of:

"Left click to cancel shortcut menus"
"Right click to activate shortcut menus"

The MouseUp CBF :

Private Sub Command3_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)


If Button = acLeftButton Then

Me.ShortcutMenu = False


ElseIf Button = acRightButton Then

Me.ShortcutMenu = True
Else
End If
End Sub

A right click, after turning on shortcut menus, will also display a
(mostly disabled) shortcut menu.

Now I think about it, that's not a good example, because the form's
ShortcutMenu Property is directly involved. Picture instead a new form,
with one textbox and one button. The button CBF is:

Private Sub Command0_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)


If Button = acLeftButton Then

Me!Text0.Value = "Left Button prodded"


ElseIf Button = acRightButton Then

Rem
Me!Text0.Value = "Right Button prodded, and I want to copy this text
with the mouse."
Rem
Else
End If
End Sub

After a right click, the shortcut menu will be displayed. This is not
what I want.

I would like to:

1. Right click the button
2. NOT see a shorcut menu.
3. See my text appear
4. Select the text, with a mouse swipe
5. Right click the highlighted (hilit?) text
6. Select "Copy" from the shortcut menu.

No matter how or where I adjust the Shortcut Menu property, if I exit
that function with shortcut menus enabled ready for step 5, I see a
shortcut menu at step 2 (or after step three, if I blinked). This is the
beast I wish to destroy.

What I've been searching for is the syntax to tell Access, "After I
right click this control, don't show the shortcut menu, but leave
shortcut menus enabled so I can use them in my next User action."

Hmm. That sentence says it all.

Just in passing, I need MouseUp rather than MouseDown for my *real*
code.

Thanks for your time.

Cheers, Alan
ala...@ihug.co.nz


Dev Ashish wrote:
>
> Hi Alan,
>
> If I can understand the problem correctly, won't something like this work?
>
> Private Sub Command0_Click()
> Me.ShortcutMenu = True
> End Sub
>
> Private Sub Command1_Click()
> Me.ShortcutMenu = False
> End Sub
>
> HTH
> -- Dev
>
> Alan Carpenter wrote in message <36E11883...@ihug.co.nz>...

> :Very Public Sub cmdExample_MouseUp(Button As Integer, Shift As Integer,

> :

Dev Ashish

unread,
Mar 7, 1999, 3:00:00 AM3/7/99
to
Hi Alan,

Ok, if I understand your question, you want to display your own shortcut
menu on the right click context right? If yes, then check out Access help
topic on ShortcutMenuBar property.

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

Alan Carpenter wrote in message <36E1EA95...@ihug.co.nz>...
:Hi Dev

:> :

Michael Kaplan

unread,
Mar 7, 1999, 3:00:00 AM3/7/99
to
The code has lots of bogus stuff in it, like

If X = doCmd.CancelEvent Then

Now, since docmd.cancelevent does not return values, this will never work.
This is not the only example of problems.

Michael

Doug Hutcheson <Doug.Hu...@dnr.qld.gov.au> wrote in message
news:7bvbmb$2k...@inet6.citec.com.au...
> Alan,
> Check the online help for MouseDown/MouseUp events and use them to
over-ride
> the default menu processing.
> Cheers,
> Doug
> PS: Love your code - does it compile without errors?
> "8-)

Doug Hutcheson

unread,
Mar 8, 1999, 3:00:00 AM3/8/99
to

Michael Kaplan

unread,
Mar 8, 1999, 3:00:00 AM3/8/99
to
Um, huh?

Its a method that takes no arguments... and returns no values... its the
equivalent of you saying:

Sub Test()
' Some code here
End Sub

and then later saying

If Test Then

which is also blatantly wrong. Test takes no params and returns no values.

Also, DoCmd.CancelEvent should almost always not be used anyway, in code
where you have a Cancel param in the event itself.'

Michael

Alan Carpenter <ala...@ihug.co.nz> wrote in message
news:36E3CEA3...@ihug.co.nz...
> Hi Michael
>
> That code doesn't have lots of bogus stuff in in. It has humungously
> giganormous dollups of bogus stuff in it, not just lots.
>
> However, Access says I'll simply have to take your word for it without
> arguing, according to this copy and paste directly from the Help File:
>
>
> Syntax
>
> DoCmd.CancelEvent
>
> This method has no arguments.
>
> Thanks for noticing, though.
>
> Cheers, Alan

Michael Kaplan

unread,
Mar 8, 1999, 3:00:00 AM3/8/99
to
Lets take a step back....

This whole idea is a pretty blatant violation of user interface guidelines,
as many (including the author of About Face and other books) will attest to.
The right click SHOULD open a shortcut menu, or nothing. Overloading it
makes it inconsistent with good Windows apps and means special training for
users. Rather than overloading the meaning, why not just add an item to the
shortcut menu that does the action?

In other words, you are going crazy trying to make your UI do something that
will be more confusing. Why bother?

Michael

Alan Carpenter <ala...@ihug.co.nz> wrote in message

news:36E3CD27...@ihug.co.nz...
> What I've been searching for is the syntax to tell Access that:


>
> After I right click this control,

> 1. Don't show a shortcut menu.
> 2. Run my code for the "button = acRightButton" condition.
> 3. Leave built-in shortcut menus enabled.
> > >

Dev Ashish

unread,
Mar 8, 1999, 3:00:00 AM3/8/99
to
Hi Alan,

FWIW, I fully agree with Michael's post about the UI stuff. But it seems to
me that the end result you want is the ability to trap the right mouse
button, run your own stuff and then show the default shortcut menu. So
something like htis (+ the error handling) should work.

'***** Code Start ******
Private Sub Command4_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Me.ShortcutMenu = False
If Button = vbKeyRButton Then
MsgBox "Hello Right Button!"
End If


Me.ShortcutMenu = True
End Sub

'***** Code End ******

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

Alan Carpenter wrote in message <36E3D063...@ihug.co.nz>...
:Hi Dev.
:
:No, not my shortcut menu. The default shortcut menu.
:
:What I've been searching for is the syntax to tell Access that:


:
:After I right click this control,
:1. Don't show a shortcut menu.
:2. Run my code for the "button = acRightButton" condition.
:3. Leave built-in shortcut menus enabled.

:
:I've run through the ShortcutMenu and ShortcutMenuBar properties, but I
:don't see what must be blindingly obvious.
:
:I've used up my share of the bandwidth in my reply to Doug, and with my
:initial "Pseudocode", which I'm beginning to regret.


:
:Thanks for your time.
:
:Cheers, Alan
:

:Dev Ashish wrote:
:>
:> Hi Alan,
:>

:> Ok, if I understand your question, you want to display your own shortcut

:>

Alan Carpenter

unread,
Mar 9, 1999, 3:00:00 AM3/9/99
to
My thanks to Doug, Dev, and Michael for their time.

What I've been searching for is the syntax to tell Access that:

After I right click this control,
1. Don't show a shortcut menu.
2. Run my code for the "button = acRightButton" condition.
3. Leave built-in shortcut menus enabled.


Doug,

The letter sequences "short", "cut", and "menu" don't appear anywhere in
the online help under either of the two headings:
MouseDown, MouseUp Events
MouseDown, MouseUp Events - Event Procedures

Obviously I'm running my code from the MouseUp event, but what I need is
the code or commands to meet the three requirements stated above.

I feel my answer lies with either the ShortcutMenu or ShortcutMenuBar
properties, but no matter what I do to either of them, my code needs to
exit with the following conditions :

Me.ShortcutMenu = True 'Because I want to use the default menu
for my next action.
Me.ShortcutMenuBar = "" 'Which gives the default.

I've tried Me.ShortcutMenu = False immediately followed by
Me.ShortcutMenu = True, which still shows the unwanted menu after my
right click on the command button.

Help for the ShortcutMenuBar Property raised my hopes with this
statement:

"If you set the ShortcutMenuBar property to a value that isn't the name
of an existing shortcut menu or menu bar macro, the form, form control,
or report won't have a shortcut menu (the default shortcut menu won't be
shown)."

It sounds as though it's exactly what I need, but closer examination
says that I can't use it. I need the default menus to carry out my next
action.

My test code, on a new blank form with one default text box Text0 and
one default command button Command0, is currently:

Private Sub Command0_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)


If Button = acLeftButton Then

Me!Text0.Value = "Left Button"


ElseIf Button = acRightButton Then

Rem
Me!Text0.Value = "Right Button"

Me.ShortcutMenu = False
'Me.Command0.ShortcutMenuBar = "Please_Go_Away"
'Me.Command0.ShortcutMenuBar = ""


Me.ShortcutMenu = True
Else
End If
End Sub

Right clicking the command button simply gives me a totally disabled
default shortcut menu. Various other combinations bordering on (and
reaching) the ridiculous won't give me the result I want.

The frustrating part of it is that I feel there must be a built-in
command such as "Cancel = True" to prevent the menu from displaying
during one particular event.

And no, Doug, I'm afraid my "Very Public Sub" doesn't compile, as
Michael has kindly pointed out.

So, I'm still looking.

Thanks to all.

Cheers, Alan


Doug Hutcheson wrote:
>
> Alan,
> Check the online help for MouseDown/MouseUp events and use them to over-ride
> the default menu processing.
> Cheers,
> Doug
> PS: Love your code - does it compile without errors?
> "8-)
>
> Alan Carpenter wrote in message <36E11883...@ihug.co.nz>...

> >Very Public Sub cmdExample_MouseUp(Button As Integer, Shift As Integer,


> >X As Single, Y As Single)

Alan Carpenter

unread,
Mar 9, 1999, 3:00:00 AM3/9/99
to

Alan Carpenter

unread,
Mar 9, 1999, 3:00:00 AM3/9/99
to
Hi Dev.

No, not my shortcut menu. The default shortcut menu.

What I've been searching for is the syntax to tell Access that:

After I right click this control,
1. Don't show a shortcut menu.
2. Run my code for the "button = acRightButton" condition.
3. Leave built-in shortcut menus enabled.

I've run through the ShortcutMenu and ShortcutMenuBar properties, but I

Alan Carpenter

unread,
Mar 11, 1999, 3:00:00 AM3/11/99
to
Michael,

My reply was a very bad pun, and my initial cry for help was an equally
weak attempt at humour. I understand what you're saying, I agree with
what you're saying.
And heartfelt thanks for your "step back" on the next post...

Alan

Michael Kaplan wrote:
>
> Um, huh?
>
> Its a method that takes no arguments... and returns no values... its the
> equivalent of you saying:
>
> Sub Test()
> ' Some code here
> End Sub
>
> and then later saying
>
> If Test Then
>
> which is also blatantly wrong. Test takes no params and returns no values.
>
> Also, DoCmd.CancelEvent should almost always not be used anyway, in code
> where you have a Cancel param in the event itself.'
>

> Michael
>
> Alan Carpenter <ala...@ihug.co.nz> wrote in message

> news:36E3CEA3...@ihug.co.nz...

Alan Carpenter

unread,
Mar 11, 1999, 3:00:00 AM3/11/99
to
(Warning! Probably not of much interest to anyone who hasn't followed
the thread, and fairly boring even if you have.)

Michael, you're right.

I think I was starting to go crazy (well, a bit of an obsession, anyway)
trying to achieve what my user wanted, and I have my answer (see
below), achieved by that "step back."

I think your questions were rhetorical, but I'll answer them anyway.

I've been converting a large Access 2.0 database to Access 8, for a
private individual, a friend. He has several forms, each containing more
command buttons and stranger code than the human mind can comfortably
encompass, with most buttons performing an action on a subset of records
with a left click, or on all records with a right click. There are
other, better ways to do it, but it's _his_ baby, it works for him, it
would have worked for his grandfather if his grandfather had owned a
computer, it's the way he's always done it, it's the way he always
intends to do it, and that's what he wants.

It's consistent within his database, and I have to admit that the design
of the forms makes it work efficiently and quickly _for him_ and for
_his_ specific needs. It's a very useful app.

So, to answer your points:

1. "inconsistent with good Windows apps and means special training for
users."

In this instance, the guy's been developing and using it since 1994. In
the context of this database, using correct Windows procedure is
inconsistent. (Hey, I'm not knocking your database, Jim.)
He would need special training to break the habit of five years.

(yet another digression. Conclude this syllogism:
Premise: This procedure is not consistent with good Windows apps.
Premise: This procedure is consistent with Jim's database.
Conclusion: (Hey, I'm not knocking your database, Jim.)
)

2. "...why not add an item to the shortcut menu?"
Answer: Two mouse clicks rather than one, repeated _many_ times in a
working day. User says "no."

3. "...you are going crazy trying to make your UI do something that will
be more confusing."
Answer: In this case, changing from the established practice would be
confusing to the single user.

4. "Why bother?"
Answer: Ok, I think you've got me there. Ever been stuck on the last
clue of a cryptic crossword? Read a novel with the last page missing?
"The first million years can be pretty bad. The second million years.."
I wanted that answer. I needed that answer. I had to have that answer.
(No, I don't get out much.)

You gave me the answer to the question I asked, and that answer was "The
right click SHOULD open a shortcut menu, or nothing." So, I needed a new
question.

My question should have been, "How can I make this user happy" The
answer doesn't have to be general, it applies to this user and database
only. He's a gadget nut, he's added so many custom buttons to Word that
he has about five screen lines left to type on (ok, I'm exaggerating. He
has at least ten lines.), he has a gadget-laden computer with a three
button mouse, he has..

HE HAS A THREE BUTTON MOUSE! And he's always wanted an app that let him
use the middle button! Nobody re-trains faster than someone who's doing
what he wants to do.

And all I have to do is change the constant acRightButton to 4, use
vbKeyRButton for my right button....
I'm joking again. A quick search and replace for acRightButton, the odd
RIGHT_BUTTON that I hadn't noticed, and everybody's happy.

There are few things worse than missing a bad joke and having it
explained at length (with obviously worse exceptions such as those
involving heavy blunt instruments and delicate parts of the body), but,
to explain at boring and bandwidth-wasting length the context of "X =
DoCmd.CancelEvent"...

I was saying something along the lines of:
I'm looking for an answer to a particular question from the members of
this newsgroup. It's possible that someone will suggest something that
I've already tried and rejected, so I'll try to eliminate some of the
possibilities. I don't know which particular suggestions these will be,
so I'll call each possible answer 'X', and deal with tht suggestion in
turn.

So,

If the suggestion that someone makes is "Use DoCmd.CancelEvent" then my
answer will be, "<snip> No"
If the suggestion that someone makes is "Use SendKeys" then my answer
will be, "<snip>even more No"

or, expressed another way,

Let X = "The suggestion that someone might make in reply to my
question."

If X = "Use DoCmd.CancelEvent" then Answer = "<snip> No"
If X = "Use SendKeys" then Answer = "<snip> No"
If X = ..

Hello? Are you still awake? Are you there? Hello?

Sorry about that.

Sincere thanks, and I now pronounce this thread pretty much used up.

Cheers, Alan


Michael Kaplan wrote:
>
> Lets take a step back....
>
> This whole idea is a pretty blatant violation of user interface guidelines,
> as many (including the author of About Face and other books) will attest to.
> The right click SHOULD open a shortcut menu, or nothing. Overloading it
> makes it inconsistent with good Windows apps and means special training for
> users. Rather than overloading the meaning, why not just add an item to the
> shortcut menu that does the action?
>
> In other words, you are going crazy trying to make your UI do something that
> will be more confusing. Why bother?
>

> Michael
>
> Alan Carpenter <ala...@ihug.co.nz> wrote in message

> news:36E3CD27...@ihug.co.nz...

Alan Carpenter

unread,
Mar 11, 1999, 3:00:00 AM3/11/99
to
Hi Dev.

My first reaction to Michael's post was, "How could I have missed that?
I've preached the rule of 'Always follow the standards', and now I'm
breaking the rule."

My solution (long, rambling, avoiding the problem and threaded to
Michael's post) still breaks the rule, because not every user has a
three button mouse.

However, the solution is for a particular user on one particular
machine, and the guy is ecstatic at the chance to use the middle mouse
button. (No, he doesn't get out much, either.)

Although it no longer matters, re-read your code below.

Point_that_gets_me_in_trouble number one: it's on mouseDown, not up. The
user's motor control isn't too good, and he sometimes clicks on the
wrong button on the form. With MouseUp, he can slide off without
releasing, then try again. I'm not surprised that you missed that part
of my post, and I've forgotten where it was - probably within a few
pages of Volume 2 Chapter 3. <g>

Point two: Run your code in a new form with or without the two
ShortcutMenu commands, and you'll get exactly the same result. You'll
get a messagebox, and when you close the messagebox you'll see a
greyed-out shortcut menu. If you can write the code that lets you close
that messagebox _without_ seeing the menu, then immediately right click
some other object (say, a text box) and see that the menu _is_ enabled,
then you'll have achieved my original objective.

Don't try it on my account, though. It may just waste more of your time
than I already have done, and as Michael said...

(Hell, and I meant this to be a brief but very sincere "thanks")

Thanks.

Alan
ala...@ihug.co.nz


Dev Ashish wrote:
>
> Hi Alan,
>

> FWIW, I fully agree with Michael's post about the UI stuff. But it seems to
> me that the end result you want is the ability to trap the right mouse
> button, run your own stuff and then show the default shortcut menu. So
> something like htis (+ the error handling) should work.
>
> '***** Code Start ******

> Private Sub Command4_MouseDown(Button As Integer, Shift As Integer, X As
> Single, Y As Single)


> Me.ShortcutMenu = False
> If Button = vbKeyRButton Then
> MsgBox "Hello Right Button!"
> End If
> Me.ShortcutMenu = True
> End Sub
> '***** Code End ******
>

> HTH
> --
> Dev Ashish (Just my $.001)
> ---------------
> The Access Web ( http://home.att.net/~dashish )
> ---------------
>

> Alan Carpenter wrote in message <36E3D063...@ihug.co.nz>...
> :Hi Dev.


> :
> :No, not my shortcut menu. The default shortcut menu.

> :
> :What I've been searching for is the syntax to tell Access that:


> :
> :After I right click this control,
> :1. Don't show a shortcut menu.
> :2. Run my code for the "button = acRightButton" condition.
> :3. Leave built-in shortcut menus enabled.

> :
> :I've run through the ShortcutMenu and ShortcutMenuBar properties, but I

> :>

0 new messages