Usage of DLAST

D

DKS

2 questions related to the usage of DLAST.

1) How do I trap that the record I am looking for does not exist?

2) I need to fill up several fields based on the last retrieved record.
Currently for each of those values I am applying the DLAST equation

field1 = DLAST ("[F1]", "Table", sCriteria)
field2 = DLAST ("[F2]", "Table", sCriteria)
..
..

Is there anyway by which I retrieve the last record once and assign the
various fields that I need? I suppose that in the above example each usage
of DLAST retrieves each time the (same) last record?

Thanks in anticipation
 
D

Douglas J. Steele

I've never understood why they bothered introducing DLast and DFirst:
they're pretty useless concepts, especially when applied to tables. Tables
do not have a predictable order, therefore First and Last are unpredictable.

What defines the "last retrieved record"? Maybe you should be using DMax or
DMin.
 
K

Klatuu

As Doug says, DFirst and DLast are pretty much useless.
What is it you want to do?
Define "the last retrieved record"
Maybe we can help
 
D

DKS

I have a set of records that are created chronologically. For a certain
item, I would like to retrieve the information filled in for the last
chronologically created item. Thus I am looking at the DLAST.

Hope that helps?



Klatuu said:
As Doug says, DFirst and DLast are pretty much useless.
What is it you want to do?
Define "the last retrieved record"
Maybe we can help
--
Dave Hargis, Microsoft Access MVP


DKS said:
2 questions related to the usage of DLAST.

1) How do I trap that the record I am looking for does not exist?

2) I need to fill up several fields based on the last retrieved record.
Currently for each of those values I am applying the DLAST equation

field1 = DLAST ("[F1]", "Table", sCriteria)
field2 = DLAST ("[F2]", "Table", sCriteria)
.
.

Is there anyway by which I retrieve the last record once and assign the
various fields that I need? I suppose that in the above example each usage
of DLAST retrieves each time the (same) last record?

Thanks in anticipation
 
K

Klatuu

When you say "created chronologically", do you mean each record has a
date/time field of when it was created? Without that, there really is no way
to know which record was created in what order.

If you do have such a field, then you want to use the DMax function. It
will return the highest value of a the field. If you are using an autonumber
field as your primary key but you don't have a date/time stamp, you can use
the DMax on the auto number field.
--
Dave Hargis, Microsoft Access MVP


DKS said:
I have a set of records that are created chronologically. For a certain
item, I would like to retrieve the information filled in for the last
chronologically created item. Thus I am looking at the DLAST.

Hope that helps?



Klatuu said:
As Doug says, DFirst and DLast are pretty much useless.
What is it you want to do?
Define "the last retrieved record"
Maybe we can help
--
Dave Hargis, Microsoft Access MVP


DKS said:
2 questions related to the usage of DLAST.

1) How do I trap that the record I am looking for does not exist?

2) I need to fill up several fields based on the last retrieved record.
Currently for each of those values I am applying the DLAST equation

field1 = DLAST ("[F1]", "Table", sCriteria)
field2 = DLAST ("[F2]", "Table", sCriteria)
.
.

Is there anyway by which I retrieve the last record once and assign the
various fields that I need? I suppose that in the above example each usage
of DLAST retrieves each time the (same) last record?

Thanks in anticipation
 
J

John W. Vinson

I have a set of records that are created chronologically. For a certain
item, I would like to retrieve the information filled in for the last
chronologically created item. Thus I am looking at the DLAST.

Then you're looking in the wrong place, thanks to Microsoft.

DLast does NOT return the most recently entered record. It sounds like it
should; it's plausible that it might; a lot of the time it even *does* - but
you can't count on it.

It returns the last record *in disk storage order*. And that order is
arbitrary; Access will put new records wherever it finds convenient. It's
often convenient to put the newest record last on the disk but sometimes it's
not!

As noted, DLast() is - by all I've been able to discover - absolutely useless.
DFirst() is useful only if you just want to retrieve any arbitrary record, and
it's faster than DLast at doing so.

If you want to retrieve the most recent chronological record then you must -
no option, no choice - have a field in the record that identifies the sequence
in which records were entered; this could be a Date/Time field defaulting to
Now(), or a sequential autonumber.

You would use a Subquery to search for the maximum value of this field in
order to pull up the most recent record.

John W. Vinson [MVP]
 

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