default value

O

Oscar

Is there a way to make the default value of something 1 greater than
the last value of that column in the table. For example, that last
"OrderNo" is 208, is there a way to make the next time I enter an order
it automatically defaults the "OrderNo" column as 209?
Thanks!
 
T

tina

to assign an incremented value to each new record in a form, you can use the
following code in the form's BeforeInsert or BeforeUpdate event procedure,
as

Me!OrderNumberControlName = Nz(DMax("OrderNumberFieldName",
"TableName"), 0) + 1

the above goes all on one line, and you must substitute the correct name of
the order number control in the form, order number field name in the form's
underlying table, and the correct name of the table.

hth
 
G

Guest

Looking up the highest number and adding 1 is fine in a single user
environment, but conflicts could arise in a multi-user environment if two
users are adding records simultaneously. A common way around this is to
store the latest number in a separate database on the server, which is opened
exclusively in code to get the next number, thus avoiding conflicts. I've
posted a demo of this, which also includes a means to reset the number at
which the next record starts, at:


http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=23839&webtag=ws-msdevapps


Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top