Description
To create an event procedure that runs when the MouseMove event occurs, set the OnMouseMove property to [Event Procedure], and click the Build button.
Syntax Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single,| Argument | Description | |
| controlname | The name of the control whose MouseMove event procedure you want to run. | |
| Button | The state of the mouse buttons when the event occurs. If you need to test for the Button argument, you can use one of the following intrinsic constants as bit masks: | |
| Constant | Description | |
| acLeftButton | The bit mask for the left mouse button. | |
| acRightButton | The bit mask for the right mouse button. | |
| acMiddleButton | The bit mask for the middle mouse button. | |
| Shift | The state of the SHIFT, CTRL, and ALT keys when the button specified by the Button argument was pressed or released. If you need to test for the Shift argument, you can use one of the following intrinsic constants as bit masks: | |
| Constant | Description | |
| acShiftMask | The bit mask for the SHIFT key. | |
| acCtrlMask | The bit mask for the CTRL key. | |
| acAltMask | The bit mask for the ALT key. | |
| X, Y | The x and y coordinates of the current location of the mouse pointer. The X and Y arguments are always expressed in twips. | 
Remarks You test for a condition by first assigning each result to a temporary Integer variable and then comparing the Shift or Button argument to an intrinsic constant. Use the And operator with the Button argument to test whether the condition is greater than 0, indicating that the left, middle, or right mouse button was pressed, as in the following example:
LeftDown = (Button And acLeftButton) > 0If ShiftDown And CtrlDown Then
    .                    ' Do this if SHIFT and CTRL keys are pressed.
    .
    .
End IfSee Also MouseMove event — macros.
Example The following example determines where the mouse is and whether the left mouse button and/or the SHIFT key is pressed. The x and y coordinates of the mouse pointer position are displayed in a label control as you move the mouse. To try the example, add the following event procedure to a form that contains a label named Coordinates:Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, _
        X As Single, Y As Single)
    Dim intShiftDown As Integer, intLeftButton As Integer
    Me!Coordinates.Caption = X & ", " & Y
    ' Use bit masks to determine state of SHIFT key and left button.
    intShiftDown = Shift And acShiftMask
    intLeftButton = Button And acLeftButton
    ' Check that SHIFT key and left button are both pressed.
    If intShiftDown And intLeftButton > 0 Then
        MsgBox "Shift key and left mouse button were pressed."
    End If
End Sub