The information in this article applies to:
SUMMARYThe DefaultEditing form property, when set to AllowEdits, allows users to both modify existing records and to add new records. Microsoft Access has no built-in mechanism to prevent users from adding new records. MORE INFORMATION
The following example demonstrates a sample, user-defined Access Basic
function that you can use to prevent users from entering new employees in
the Employees form in the sample database NWIND.MDB:
How PreventNew() WorksWhenever you navigate to a different record, the OnCurrent property runs the PreventNew() function. This function attempts to reference the Bookmark property associated with the current record. All records are assigned a string, called a bookmark, that uniquely identifies each record.However, a new record that has not yet been saved has no bookmark associated with it. Any attempt to reference the bookmark of a new record generates an error message. If an error occurs, the PreventNew() function immediately performs a GoToRecord action to navigate to the last record in the form. Using PreventNew() with Forms That Contain No RecordsIf the table or query that the form is based on contains no records, PreventNew() does not prevent you from adding a new record to the form. You must first test to see if records exist in the table or query prior to opening the form. You can use the following Access Basic function to test whether records exist in a table or query.
Given the name of the table or query, this function will return True (-1) if records exist, or False (0) if no records exist. Another method you can use is the DCount() function. However, the DCount() function may be significantly slower than the RecordsExist() function in that it must count all the records in the database whereas RecordsExist simply tests to see if there is a "first" record in the recordset.
Keywords : kbprg FmsHowto PgmObj |
Last Reviewed: March 24, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |