HandsOn Writing the Form MouseDown Event Procedure

1. Create a new form based on the Products table. Add all the available fields to the form. Save this form as Products Test.

2. Click the Properties button to activate the Form properties sheet.

3. In the Form properties sheet, click the Event tab. Click next to the On Mouse Down event property and choose [Event Procedure] from the drop-down box. Click the Build button (...).

4. Place the code shown below in the Form_MouseDown event.

Private Sub Form_MouseDown(Button As Integer, _ Shift As Integer, _ X As Single, _ Y As Single) Debug.Print "Mouse Down"

Select Case Shift Case 0

MsgBox "You did not press a key." Case 1 ' or acShiftMask

MsgBox "You pressed SHIFT." Case 2 ' or acCtrlMask

MsgBox "You pressed CTRL." Case 3

MsgBox "You pressed CTRL and SHIFT." Case 4 ' or acAltMask

MsgBox "You pressed ALT." Case 5

MsgBox "You pressed ALT and SHIFT." Case 6

MsgBox "You pressed CTRL and ALT." Case 7

MsgBox "You pressed CTRL, ALT, and SHIFT." End Select

If Button = 1 Then ' acLeftButton

MsgBox "You pressed the left button." ElseIf Button = 2 Then 'acRightButton

MsgBox "You pressed the right button." ElseIf Button = 4 Then 'acMiddleButton

MsgBox "You pressed the middle button." End If End Sub

5. To test the above event procedure, switch to the Products Test form and open it in Form view. Click on the record selector while holding down any mouse button and pressing the Shift, Ctrl, or Alt keys or their combinations.

Event Programming in Forms and Reports

6. Close the Products Test form.

0 0

Post a comment