Form_MouseDown not triggering

G

greg

I want to trigger an event if the mouse is clicked anywhere on a form. This
seems pretty straight forward, but it does not seem to work in access -
surely I must be doing something wrong?? The code I am using is:

Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)
MsgBox ("mouse coordinates are X:" & X & " ,Y:" & Y)
End Sub
 
D

Douglas J. Steele

You probably want to put the code in the Detail section's MouseDown event,
not the form's.
 
G

greg

Doug,
To explain a bit more : When using the Detail section, the mousedown event
is only triggered in blank areas of the form. The areas I really want to
trigger are on rectangle controls on the form (hence why I need the form
mousedown event- which is supposed to work?? - this may be a bug??). I can't
use the seperate rectangle mousedown event for each, as there are a variable
number of rectangles (in the hundreds). Ideally, I would like to use a class
module for all rectangles - but class modules do not appear to work in access
for any mouse events??? - another bug???
 
D

Douglas J. Steele

I just put your code into a form's Detail_MouseDown event, and it works for
clicking on rectangle on the form for me. Of course, the rectangles were in
the detail section. What part of the form are yours in?
 
G

greg

Doug,
More info I forgot to mention: I am guessing that your rectangle is
'transparent' (this works for me too)- where the rectangles I am using are
'normal' with a back colour (which doesn't work using the Detail_MouseDown
event). But at least this is an option I hadn't considered - There does not
appear to be any other possible solution.
 
D

David W. Fenton

More info I forgot to mention: I am guessing that your rectangle
is 'transparent' (this works for me too)- where the rectangles I
am using are 'normal' with a back colour (which doesn't work using
the Detail_MouseDown event). But at least this is an option I
hadn't considered - There does not appear to be any other possible
solution.

I you want to do something when a form is clicked, why are you using
MouseDown instead of OnClick? The MouseDown event can fire without
the completion of the click, something I do all the time when I
start to click on something and change my mind (I pull the mouse
pointer off the object before releasing the button). The OnClick
event requires both the MouseDown and MouseUp events to fire, and
that's a good thing.

In general, I'm suspicious of programming anything to respond to a
single mouse click in Access other than a command button, simply
because it's too easy for a user to accidentally execute the event.
Have you consider the doubleclick event instead?
 
G

greg

Thanks for the feedback, but the reason I went for mouse down, is because I
actually want to reposition the rectangle controls with the mouse by
'dragging' them with the mouse down. The mousedown would also provide me with
the pointer co-ordinates so I can identify which rectangle is being clicked.

With that said - I am desperate, so I tried a Form_Click and Form_DblClick ,
but these are not acknowledged either.
 
D

David W. Fenton

Thanks for the feedback, but the reason I went for mouse down, is
because I actually want to reposition the rectangle controls with
the mouse by 'dragging' them with the mouse down. The mousedown
would also provide me with the pointer co-ordinates so I can
identify which rectangle is being clicked.

Ah -- that's the correct justification for use MouseDown. That
wasn't clear to me from what I'd read.
With that said - I am desperate, so I tried a Form_Click and
Form_DblClick , but these are not acknowledged either.

I forget, but do rectangles have mouse events? If so, maybe you need
to call your code in them as well as in the form's mouse events.
 
G

greg

Rectangles do have mouse events, but - (more information that I neglected to
provide), I have a large (>300), variable number of rectangles to deal with
and dont want to code for each one - hence the form event sounded like a good
idea.

However, with that said, I have just managed to sucessfully achieve my
objective by using a mousedown in a class module.

Thanks for your thoughts.
 
D

David W. Fenton

Rectangles do have mouse events, but - (more information that I
neglected to provide), I have a large (>300), variable number of
rectangles to deal with and dont want to code for each one - hence
the form event sounded like a good idea.

Well, it's quite easy to assign a function as an event. This works
very well with controls that can get the focus since you can use
Screen.Activecontrol to figure out which control the code should
operate on. I don't know that there's any way to do
However, with that said, I have just managed to sucessfully
achieve my objective by using a mousedown in a class module.

Great! You might want to post the basics of that approach or
pointers to where you got the idea so that others who have similar
problems who come across this thread in Google Groups could benefit
from your experience.
 
G

greg

for anyone interested - here is how I resolved my issue using the mousedown
event in a class module:

' In a FORM: (with 2 rectangles called Box0, and Box1)
Private boxes() As New Class1
Private Sub Form_Load()
ReDim Preserve boxes(1)
Set boxes(0).RectControl = Me.Box0
Set boxes(1).RectControl = Me.Box1
End Sub

' In a Class Module called 'Class1'
Private WithEvents RectGroup As Access.Rectangle

Public Property Set RectControl(pctl as Access.Control)
If TypeOf pctl Is Access.Rectangle Then
Set RectGroup = pctl
RectGroup.OnMouseDown = "[Event Procedure]"
End If
End Property

Private Sub RectGroup_Mousedown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
MsgBox ("you pressed " & RectGroup.Name)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top