Need Query for Most Recent Entry

  • Thread starter Thread starter Inquisitor_Malice
  • Start date Start date
I

Inquisitor_Malice

Guest
Hello Everyone,

I need a hand with making a query that will all me to sort a table and then select the most recently entered sample by date. Would anyone be able to assist me with this?

Thanks-
 
Well, the code for sorting a table is

OrderBy = "[Field you need to sort by]"
OrderByOn = True

Or in a form, go to the form properties and go to the "Order By" field...there type:

"Name of Field you wish to sort by, no quotes if one word but use brackets if its not" ASC or DESC, for Ascending and Descending..

Alternately, you open the table as a datasheet and sort how you wish, then save the table...it will automatically save the sort. In a query design view, there is a option to "Sort By" in any given field, either ascending or descending.

When you design the query, drop the date field (I'm assuming there is a field here, so you can select the "most recent") into the query and in the Criteria: row type a statement enclosed in brackets---For instance, [Enter the date of the record:].

When you run the query, Access will give you a message box with your prompt (whatever you typed in the brackets) and a blank field....where you can type "9/19/2001" (minus the quotes) or whatever format you've stored your date in. This method isn't useful if you store the date like "July 31, 2001"...but there are other procedures....the query should return the appropriate record.

For a range of dates, same process applies, only in the Criteria: row you type a calling statement like this :
Between [Type Beginning Date Here:] And [Type Ending Date Here:]

These are criterion that will prompt you for input every time you run the query...if you want a more specific (but less modifiable) method, some Date-field criterion are as follows: (minus quotes of course)

"<Date()+10" --will display all records with a record in the last ten days from the present

"Year([Year Field if you have one])=XXXX" Where the X's are the format of the year, like "1979"

Hope this offers some assistance.

Kate
 
Yeah, I know how to sort by date and do for example a 30 day sort. After the sort if completed, I need to be able to retrieve the most recent record for a report. I have tried fixed date selection, but we have multiple samples entered each day. And if we don't have any samples entered for a week, the fixed day sort/selection doesn't work either. Is there a function or macro that would give me the most recent entry based on either date and/or record number.
 
Look at the help file on 'topvalues'for SQL Queries. TOP 1 should give you the 'highest' value for whatever field you're confident will be latest (one with NOW() as its source would be a good candidate, so would an autonumber).

HTH,
David R
 

Users who are viewing this thread

Back
Top Bottom