ACC: Cannot Use Counter to Determine If Record Is New RecordLast reviewed: August 29, 1997Article ID: Q112109 |
The information in this article applies to:
SYMPTOMSModerate: Requires basic macro, coding, and interoperability skills. The status of the AutoNumber field (or Counter field in version 2.0) cannot be used to determine if the current record is the new record.
CAUSEIn Microsoft Access version 1.x, the Counter field was Null until the record was saved (that is, you moved to the next record, or clicked Save Record on the File menu). Therefore, if you checked the Counter field (using the IsNull() function) and it was Null, then the record being edited was a new one. If not, then it was an existing record. The usual method was to put the following expression in the form's BeforeUpdate property:
IsNull([<counterfieldname>])In Microsoft Access 2.0 and later, however, the AutoNumber field is updated as soon as you begin inserting a new record, which invalidates the method described above for Microsoft Access version 1.x.
RESOLUTION
In Microsoft Access 7.0 and 97This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual. There is a property called NewRecord. This property can be checked in the BeforeUpdate of the form to determine if the record is a new one. For example:
In Microsoft Access 2.0To determine if the current record is a new record using a Counter field in Microsoft Access 2.0, you can check the OldValue property. OldValue property will return Null for a new record. To do this, use the following expression in the form's BeforeUpdate property:
IsNull([<counterfieldname>].OldValue)For another technique that does not require the use of a Counter field, please see the following article here in the Microsoft Knowledge Base:
ARTICLE-ID: Q112292 TITLE: ACC: How to Determine if the Current Record Is the New Record REFERENCESFor more information about the NewRecord property, search the Help Index for "NewRecord property." For more information about the OldValue property, search the Help Index for "OldValue."
|
Additional query words: forms
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |