Forms

3.5 Preventing Access 97 from Creating New Records...
  Christopher A. Kittila, AlittiK Technologies, Inc. of Sugar Land, Texas US.
(D)
Preventing Access 97 from Creating New Records When Using PageDown at the End of a Form.

(R)
While you can easily set the behavior of the tab key in a form to either wrap around the current page/record, the same is not true of the PageDown key. When a user presses page down at the bottom of a form (and the form is in add mode) a new record is always generated. This problem is extremely scary to the novice user, who suddenly sees the form go blank. Access does not even give you the courtesy of moving your cursor to the top of the blank page. To make matters worse, if the form is dependent on getting data from a parent form (such as a primary key) the form will issue a save error when it is closed.

To stop this behavior we set the KeyPreview field to "YES" and add a KeyUP event. The KeyUP event checks the status of some critical text field in the form (such as a text box containing the record ID field). This field must be set in the form properties to some default value, such as zero. It is useful to choose a primary key field because this value should be anything but zero. If the value is zero, it suggests that the user has inadvertantly moved to a new record. If this situation happens the KeyUp event automatically moves the user back to the previous record.

KeyUP Event

If [txtPrimaryKeyID] = 0 Then DoCmd.GoToRecord , , acPrevious

This solution very useful when you want to restrict users from adding more than one form based sub-record at a time.


Se pensate di avere del materiale freeware interessante e volete pubblicarlo, allora leggete qui.