First and foremost I would like to say that I am new to Access and please excuse me in advance if my question is silly. That said, I have created a very simple form in Access and want to display a message every time the mouse has been pressed. For that reason I added the following code attached to the "Mouse Down" event in Access:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox "Click"
End Sub
However, it doesn't work no matter how many times I click my mouse. I have tried to move it to "Mouse Up" and "Mouse Move", but it seems that the mouse events cannot be triggered. That said, when I put the event to "Key Press" everything is working fine.
I would be really grateful if you can maybe guess what the cause of the problem is. Could it be that I am using a Razor mouse? It seems weird that the key press trigger was successful, but none of the mouse ones are working. Thank you in advance!
CodePudding user response:
You're likely looking for Detail_MouseDown
Form_MouseDown
affects the record selector.
The entire form body is the details section, and that's affected by Details_MouseDown
.
Note that, as stated earlier, records and labels have separate MouseDown
events. If you want to capture all mouse clicks on a form, one approach is to have an object that handles these events (and possibly redirects them back to the form) and initialize this on Form_Load
for each control. See this for some guidance, but note you unfortunately need objects for each kind of control.
CodePudding user response:
From: https://docs.microsoft.com/en-us/office/vba/api/access.form.mousedown
"To cause a MouseDown event for a form to occur, press the mouse button in a blank area or record selector on the form. To cause a MouseDown event for a form section to occur, press the mouse button in a blank area of the form section."
So you need a "blank area" to click on.