Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display the last n records in a subform

Status
Not open for further replies.

CHTHOMAS

Programmer
Jun 16, 1999
106
AE
Can any one help me on how to display only the last n records in a subfrom.<br>
Charley
 
Is there a field/column that indicates the order the rows were added in? For example, an autonumber or date/time field.
 
I would get the record count of the recordsource of the subform, then loop through the last n records and change the recordsource of the subform to " where identityfield = {the identity fields of the last n records}" Off of the top of my head, this is what I come up with...<br>
<br>
J = 0<br>
do while not rst.eof<br>
If j = n then<br>
sql = sql2 & " where [autofield] = " & rst!autofield<br>
sql2 = sql & " and " <br>
end if<br>
j = j + 1<br>
loop<br>
<br>
subform.recordsource = "select * from rst" & sql
 
(perhaps being a little simplistic about this!)<br>
<br>
SELECT TOP n<br>
tblUser.field1, <br>
tblUser.field2, <br>
tblUser.field3<br>
FROM tblUser<br>
WHERE tblUser.field1 &lt; criteria<br>
ORDER BY tblUser.field2 desc;<br>
<br>
well, you USED to be able to do that!<br>

 
Did you resolve this? I have a similar problem and was wondering what worked for you.<br>
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top