ACC2000: Cannot Use AutoNumber to Determine If Record Is New Record (210411)
The information in this article applies to:
This article was previously published under Q210411 SYMPTOMSIsNull([AutoNumber Fieldname]) no longer returns True while entering a new record.
CAUSE
In Access, the AutoNumber field is updated as soon as you begin inserting a new record.
RESOLUTIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Access includes a property called NewRecord. You can check this property in the
BeforeUpdate event of a form to determine if the current record is a new one. For example:
- Open the sample database Northwind.mdb.
- Open the Categories form in Design view.
- Add the following code to the BeforeUpdate property of the form:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim newmsg As String
Dim newrec As Integer
newrec = Me.NewRecord
If newrec = True Then
newmsg = "This is a new record"
MsgBox newmsg
End If
End Sub
- Close the module.
- Open the form in Form view and click the new record selector.
- Type Bogus Category in the Category Name box and click the new record selector again. Note that a message stating, "This is a new record" appears. Click OK and you will be on a new record.
REFERENCESFor more information about the NewRecord property, click Microsoft Access Help on the
Help menu, type NewRecord Property in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned.
For more information about the OldValue property, click Microsoft Access Help on the
Help menu, type OldValue Property in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned.
Modification Type: | Major | Last Reviewed: | 6/23/2005 |
---|
Keywords: | kbprb kbusage KB210411 |
---|
|