Most Recent

T

tryn2learn

Good afternoon,

I'm trying to run a query that will only pull the most recent entry.

I have my table set up with a field (Auto-Number) i just don't know how to
make it pull the most recent entry (only).

thank you for your help.
 
J

Jerry Whittle

Autonumbers are not a 100% guaranteed to be sequential so that could be a
problem. If you want to be almost 100% sure, you need a field in your table
that has a data type of Date/Time and a default value of Now().

You can try the autonumber field with something like:
SELECT TOP 1 YourTable.*
FROM YourTable
ORDER BY YourTable.Autonumber_Field DESC;
 
T

tryn2learn

Thank you Jerry,

in light of the auto number not being 100%... i would like to go the route
you suggested. "you need a field in your table that has a data type of
Date/Time and a default value of Now()."

in doing what you suggested what kind of code will i need or can i use the
same code you've already posted?

thank you so much for your help.
 
J

Jerry Whittle

Yes you could change the SQL statement below to sort on the Date field that
has Now() as the default. Two problems with that though.

1. Now() returns times down to the second based on the computer adding the
record. It's possible that two or more records could be added at the same
time in a multi-user environment or if you import the data from another
source.

2. A default such as Now() only works for new records. You'll have to figure
what to do about existing records. However if you just want the latest, that
will take care of itself after adding the first new record.
 
T

tryn2learn

This is great because for this report all i want is the information of the
most recent record.

thank you again... have a great day, a Merry Christmas and Happy new Year.
-Patrick
 
T

tryn2learn

Sorry to bother you again, i am trying to apply the code but i'm having no
success... i know it's not the code, but how i'm trying to do it.

the name of my table is: Tech_Req
in my form i have a field that contains (date requested) the field name in
the table is: Date_Req

Do i post the code in the query in Criteria or somewhere in the table?
again thank you i truly appreciate your help... yet again.
 
J

Jerry Whittle

Open up a new query in design view based on the table. Go to View, SQL View
on the menu. Replace what is there with:

SELECT TOP 1 Tech_Req.*
FROM Tech_Req
ORDER BY Tech_Req.Date_Req DESC

OR

Create a new query based on the Tech_Req table. Make sure that the Date_Req
field is brought down to a column and sort it in descending order. Now for
the fun part: Right-click up in the gray area near the table. Go to down to
Properties. Manually change Top Values from All to 1.
 

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

Top