HandsOn Writing the Form Click Event Procedure

1. Create a new form with two text boxes. Position both text boxes starting at 1 inch on the horizontal ruler. Save the form as Mouse Test.

2. Click the Properties button to activate the Form properties sheet, if it is not already open.

Event Programming in Forms and Reports

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

4. Access opens the Visual Basic Editor window and writes the stub of the Form_Click event procedure. Complete the code of the Form_Click event procedure as shown below.

Private Sub Form_Click()

MsgBox "Form Click Event Occurred." Me.Text0.Left = Text0.Left + 1440 End Sub

The first text box control placed on the form is automatically named TextO. The Left property is used to specify an object's location on a form or report. The above procedure moves a text box control one inch to the right. Screen measurements are expressed in units called twips and there are 1440 twips per inch. Thus, to calculate the new position of the text box, you must add 1440 to the current position.

5. To test the above event procedure, open the Mouse Test form in Form view. Click on the record selector (a small box or bar to the left of a record). This will cause the Form_Click event procedure code to execute and you will see a message box. After clicking OK in response to the message, the first text box control will move one inch to the right.

0 0

Post a comment