Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing mouse events within VBA

Status
Not open for further replies.

MartinF

Technical User
Sep 19, 2000
143
FR
Hi,

I have some code that activates when the mouse button is pressed over a control. I have a loop that executes and i require it to exit only when the mouse button is released. During the loop i also need to return the mouse x and y co-ordinates.

If anyone could tell me how to capture these type of mouse events in VBA i would be very grateful.

Thanks
 
Check out the OnMouseDown, and OnMouseUP events. The events return the following values. x position, y position, shift(key on keyboard that is pressed), button(mouse button that was clicked). If you need any more help let me know. The hardest questions always have the easiest answers.
 
Hi,

Thanks for responding.

I dont think i really explained my question too well.

The code starts off like this when the mouse button is held down over a control:

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

With DragButton
.Left = X
.Top = Y
.Visible = True
End With


What i need now within this procedure is a loop that only exits when the mouse button is released. Another thing i have discovered is that the X and Y coordidnates that are passed into the event are the mouse x, y within that control, not the actual mouse x, y coordinates relative to its position on the form. 'DragButton' is a hidden label which sets itself to the mouse coordinates and becomes visible when the above procedure is activated, however it always appears near the top left hand corner of the form.

What i am ultimately trying to achieve is drag and drop capabilities within Access. 'DragButton' is the icon that follows the mouse around whilst the mouse button is held down. I have looked at the examples you get shipped with Access, but these are not really suitable for what i am trying to achieve.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top