English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi! I need to return the last record in a simple table in MS Access. I have a form that's pulling certain values from the table, and I need it to get the physically last record.
Is there a function for that?

2007-03-03 12:59:09 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

This is relatively simple to do and can be done one of two ways. The first way requires you to sort a table and by find the last you are finding the end of a DECENDING sort. You can then use a SELECT TOP 1 * to return the first record of the decending sort. Of course this requires sorting the table.

The second method allows you to find the last record of an unsorted table. The only requirement is that you have a single field PRIMARY KEY like an autonumber RecID field ect...


First create a summation or total query on the recID field.
Do this by adding the table in the query designer and clicking on just the recID. Then on the tool bar click on the sigma (Backwards looking bent E). This converts the query to a total and adds another line with a drop down box under the field. From the drop down box you can select from several math functions, SUN,AVG ect...
But most importantly you can select FIRST or LAST.

Select LAST and run the query . it will return the recID of the last record in the table. Save this query as Q_LastRecord_myTable

now make a second query:

This query will return all of the fields of the last record. It will use the results of the LastRecord query yourjust created to extract that record

So when you create this new query inm the designer add the table and the query LastRecord. Then creat a join between the recID fields in the table and te query and return all fields from teh table.

Run this query and you will have the last record of the table. (unsorted)

2007-03-03 14:09:32 · answer #1 · answered by MarkG 7 · 0 0

Finding records based on the order in which they were entered involves two things - sorting the records in natural order, and optionally, limiting the view to display only the records that were first or last. When records are sorted in natural order, the records entered first appear at the top and the records entered most recently appear at the bottom.

2007-03-03 13:13:59 · answer #2 · answered by Indiana Frenchman 7 · 0 0

I will ask my friend who is an MS Access programmer and post the anwer if he can tell me more then I know. You might be able to use the help in MS access as I use Access for a few things from work. It might be a function or might be a macro I have to wait to find out from my techie friend and will post once I hear back from him.

2007-03-03 13:23:11 · answer #3 · answered by Anonymous · 0 1

pick * from Transtable the position pk=(pick max(Transdate), pk from TransTable); only replace the pk because the team of fields that uniquely identifies the line. sounds like it truly is client# and TransDate are your unique identifiers. Eric

2016-12-05 05:10:44 · answer #4 · answered by ? 3 · 0 0

fedest.com, questions and answers