Strange Right Click behaviour - On Mouse Down (1 Viewer)

Lateral

Registered User.
Local time
Today, 13:12
Joined
Aug 28, 2013
Messages
388
Hi guys


I've been trying to figure out the following for some time.


I have the following code on the On Mouse Down event of a TextBox control on a form in Continuous form mode that is in a Tabbed form that I have been using to try to determine the cause of my problem:


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

Dim sWhere As String

If Button = acLeftButton Then
MsgBox "You pressed the left button."

sWhere = "[PartID] = " & Me.PartID

DoCmd.OpenForm "fPartsEdit", acNormal, , sWhere

End If

If Button = acRightButton Then
MsgBox "You pressed the right button."

sWhere = "[PartID] = " & Me.PartID

DoCmd.OpenForm "fPartsEdit", acNormal, , sWhere
End If

If Button = acMiddleButton Then
MsgBox "You pressed the middle button."

sWhere = "[PartID] = " & Me.PartID

DoCmd.OpenForm "fPartsEdit", acNormal, , sWhere
End If

End Sub

The above detects if the right, middle or left buttons on the mouse is clicked and then opens a form called "fPartsEdit"

If I left click or middle click, the forms opens on top of the main form which is exactly what I want. If I right click, the "fPartsEdit" form is opened behind the main form....why????

I want to use the right click but it is acting weird...

Thanks for any help
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:12
Joined
May 7, 2009
Messages
19,247
right click is used as shortcut menu, so this system even is called first before your user defined sub.
 

Lateral

Registered User.
Local time
Today, 13:12
Joined
Aug 28, 2013
Messages
388
Thanks for the quick reply.


Are you saying that I can't use it to open a form?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:12
Joined
May 7, 2009
Messages
19,247
you can, but after opening it you need to SetFocus to it.
 

Lateral

Registered User.
Local time
Today, 13:12
Joined
Aug 28, 2013
Messages
388
Thanks mate, I'll try that and let you know the outcome..


Cheers
Greg
 

Lateral

Registered User.
Local time
Today, 13:12
Joined
Aug 28, 2013
Messages
388
I just tried the following but it doesn't bring the form to the front of the Main form:


I have also tried to point to a specific control of the fPartsEdit form without any luck:


If Button = acRightButton Then

sWhere = "[PartID] = " & Me.PartID

DoCmd.OpenForm "fPartsEdit", acNormal, , sWhere

Forms("fPartsEdit").SetFocus

End If


Also, if I add a Button to the main form containing the Forms("fPartsEdit").SetFocus then it brings tfPartsEdit to the front...


It looks like the right click handles things differently...
 
Last edited:

Minty

AWF VIP
Local time
Today, 21:12
Joined
Jul 26, 2013
Messages
10,371
Quote from the interwebs
The Latin adjective sinister/sinistra/sinistrum originally meant "left" but took on meanings of "evil" or "unlucky" by the Classical Latin era, and this double meaning survives in European derivatives of Latin, and in the English word "sinister".

My poor attempt at left / right humour
 

isladogs

MVP / VIP
Local time
Today, 21:12
Joined
Jan 14, 2017
Messages
18,246
As a sinistral, I (am pretending to) take personal offence at this unnecessary mocking of our special talents and may cut them out of this thread....using left handed scissors of course ;)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:12
Joined
May 7, 2009
Messages
19,247
move your code to MouseUp event instead.
 

isladogs

MVP / VIP
Local time
Today, 21:12
Joined
Jan 14, 2017
Messages
18,246
It seems an odd way of opening a form to me but I do have a solution for you

I've just tested something similar & get the same behaviour as you when using the right mouse button to open a standard form. The right button must affect the z-order

However, if your second form is a popup it will work just fine as that forces it to the top
If you don't want it to be permanently as popup then use the following to change it temporarily using code. This can only be done when that form is open in design view.

Code:
If Button = acRightButton Then

   sWhere = "[PartID] = " & Me.PartID

   [COLOR="DarkRed"]DoCmd.OpenForm "fPartsEdit", acDesign
   Forms!fPartsEdit.PopUp = True[/COLOR]

   DoCmd.OpenForm "fPartsEdit", acNormal, , sWhere

   Forms("fPartsEdit").SetFocus

End If

You will also need to use code like this somewhere else to reset it again
Code:
DoCmd.OpenForm "fPartsEdit", acDesign
   Forms!fPartsEdit.PopUp = False
   DoCmd.Close acForm, "fPartsEdit"

FYI - nothing happens at all when I use the middle mouse button in this way - so that must depend on how it is programmed.
 

isladogs

MVP / VIP
Local time
Today, 21:12
Joined
Jan 14, 2017
Messages
18,246
You're welcome
I've tested it & know it works
 

Micron

AWF VIP
Local time
Today, 16:12
Joined
Oct 20, 2018
Messages
3,478
on the form which you right click
Forms!form1.ShortcutMenu = False

That should do it.
(I should mention that you'll have to cycle it back on at the end of the right click IF block).
 
Last edited:

Users who are viewing this thread

Top Bottom