PC Review


Reply
Thread Tools Rate Thread

Last record plus 1

 
 
Whitney
Guest
Posts: n/a
 
      8th Oct 2008
I have a table with a number field. I would like to add a new record that
looks at the last record and auto generates a number of the last record plus
1.

Last record : 1000
New record: 1001

How can I do this? Does the field type have to be an auto number?

P.s. I'm using a form to create the new record and enter the data. I need
the form field to display the new auto generated number as well. Please advise
 
Reply With Quote
 
 
 
 
Rick Brandt
Guest
Posts: n/a
 
      8th Oct 2008
Whitney wrote:
> I have a table with a number field. I would like to add a new record
> that looks at the last record and auto generates a number of the last
> record plus 1.
>
> Last record : 1000
> New record: 1001
>
> How can I do this? Does the field type have to be an auto number?
>
> P.s. I'm using a form to create the new record and enter the data. I
> need
> the form field to display the new auto generated number as well.
> Please advise


You can set the DefaultValue property of the TextBox on your form to...

=DMax("FieldName", "TableName") + 1

That will NOT work if you have multiple users simultaneously entering
records and it will NOT work on a continous or datasheet view form. For
both of those situations you need to wait until the BeforeUpdate event to
grab the value and assign it to the control. That means that the user will
not see the value until after they save the new record...

If Me.NewRecord Then
Me.TextBoxName =DMax("FieldName", "TableName") + 1
End If

If you need either of those to work on a completely empty table with no
existing records then you would need to add the Nz() function like...

=Nz(DMax("FieldName", "TableName"),0) + 1

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"STAR PLUS" STAR PLUS LIVE" "STAR PLUS TV" "STAR PLUS DRAMAS" "STAR kaka DIY PC 0 7th Jul 2009 04:09 PM
Last record problem, is it really the last record? =?Utf-8?B?ZWZhbmRhbmdv?= Microsoft Access Form Coding 1 23rd Jul 2007 01:44 AM
Last record problem, is it really the last record? =?Utf-8?B?ZWZhbmRhbmdv?= Microsoft Access VBA Modules 1 23rd Jul 2007 01:44 AM
Last Record plus One =?Utf-8?B?SXJhbQ==?= Microsoft Access Forms 2 7th Apr 2007 11:50 PM
Form code: how do I run code every time a record is "loaded" by going to next record, last record, etc. Dave R. Microsoft Access Macros 1 24th Jun 2005 07:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:08 AM.