View Single Post
  #5  
Old December 13th, 2008, 01:26 AM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default update number field automatically?

On Fri, 12 Dec 2008 14:04:10 -0800, Patttt
wrote:

I have an existing table that has a number field as the primary key. I want
it to replicate the autonumber feature by adding the next number in sequence
when a new record is added, but I can't change it to an autonumber field and
keep the existing data. Can it be done? Thanks! Pat


You can use a bit of VBA code in the Form's BeforeInsert event (yes, you must
use a Form, table datasheets have no usable events):

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!IDField = NZ(DMax("[IDField]", "[tablename]")) + 1
End Sub
--

John W. Vinson [MVP]