Getting data from last record in table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application where I'm tracking check information. The first field
in the form is the check number. Most of the time the number will be the
previous entry plus 1 so I want to have the default value for this field be
whatever the last check number was plus 1. In the default entry for this
field I have:
=DLast("[Check Number]","TblChecks")+1

This has been working fine for months but all of a sudden I am getting a
number that corresponds to a previously entered check. I have tried doing a
repair and compact on the database to no avail.

If I go to the "immediate" field for Visual Basic and run the DLast command
it really does return a record that was NOT the last record added to the
table.

Can anyone help me?

Will
 
DLast and DFirst aren't particularly useful functions unless you can control
the order in which the data's arranged in the table. While you can control
the sort order in queries, you you can't in tables. To be honest, I don't
understand why Microsoft included those functions.

Try using DMax instead.
 
Thanks, Doug. Unfortunately DMax won't work because there are a couple of
different check sequences that are being used & if I'm entering data from my
checks I want the next check number in my sequence to appear, not someone
elses.

Will

Douglas J Steele said:
DLast and DFirst aren't particularly useful functions unless you can control
the order in which the data's arranged in the table. While you can control
the sort order in queries, you you can't in tables. To be honest, I don't
understand why Microsoft included those functions.

Try using DMax instead.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


traveler said:
I have an application where I'm tracking check information. The first field
in the form is the check number. Most of the time the number will be the
previous entry plus 1 so I want to have the default value for this field be
whatever the last check number was plus 1. In the default entry for this
field I have:
=DLast("[Check Number]","TblChecks")+1

This has been working fine for months but all of a sudden I am getting a
number that corresponds to a previously entered check. I have tried doing a
repair and compact on the database to no avail.

If I go to the "immediate" field for Visual Basic and run the DLast command
it really does return a record that was NOT the last record added to the
table.

Can anyone help me?

Will
 
traveler said:
Thanks, Doug. Unfortunately DMax won't work because there are a
couple of different check sequences that are being used & if I'm
entering data from my checks I want the next check number in my
sequence to appear, not someone elses.

Then you need an incrementing field or a DateTime field that will provide an
"order of entry". There is nothing in Access that inherantly "knows" the order
that records were entered in.
 
Back
Top