Show last 'X' records in a subform

S

Steve S

Have a form that the user uses to input data to create new records. these
records are displayed in a subform just below the data entry fields. I now
have the subform set to display all records in reverse order so the user can
see the latest added at the top fo the subform(decending order). this is
confusing for some users ( if not all). they want to see the latest record
entered at the bottom of the subform (ascending order) which means they have
to hit the scroll bar to get to the bottom of the list. Pain in the...

Is there a way to set the subform properties to show the last X records in
ascending order instead of the first x records???

Any help is appreciated.
 
T

Tony Toews [MVP]

Steve S said:
Have a form that the user uses to input data to create new records. these
records are displayed in a subform just below the data entry fields. I now
have the subform set to display all records in reverse order so the user can
see the latest added at the top fo the subform(decending order). this is
confusing for some users ( if not all). they want to see the latest record
entered at the bottom of the subform (ascending order) which means they have
to hit the scroll bar to get to the bottom of the list. Pain in the...

Is there a way to set the subform properties to show the last X records in
ascending order instead of the first x records???

No, but you can use the subforms recordsetclone, the recordset
movelast, moveprevious and bookmark to set the subform to the desired
position.

I've been meaning to do a web page on this topic and hopefully will do
it in the next day or so. So check back here.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
S

Steve S

Sounds like a solution is on the way. I will chack back in a few days.
thanks much
 
J

John Smith

Create a 'TOP' query based on the table:

SELECT TOP 5 somedate, otherfields
FROM sometable
ORDER BY somedate DESC;

Then base the subform on a query of that query ordered by the ascending date
should give you what the users want. The '5' should be whatever number of
records you need.

SELECT *
FROM topquery
ORDER BY somedate ;

HTH
John
##################################
Don't Print - Save trees
 
T

Tony Toews [MVP]

John Smith said:
Create a 'TOP' query based on the table:

However the user won't be able to see the records previous to the ones
selected by the TOP query. What I want to do, and what Steve wants,
and which I have working except for one bug, is display the last five
but allow the user to scroll backwards and view the rest of the
records too.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
M

Marshall Barton

Steve said:
Have a form that the user uses to input data to create new records. these
records are displayed in a subform just below the data entry fields. I now
have the subform set to display all records in reverse order so the user can
see the latest added at the top fo the subform(decending order). this is
confusing for some users ( if not all). they want to see the latest record
entered at the bottom of the subform (ascending order) which means they have
to hit the scroll bar to get to the bottom of the list. Pain in the...

Is there a way to set the subform properties to show the last X records in
ascending order instead of the first x records???


You can use this code in the Load event:

With Me.RecordsetClone
If .RecordCount > 5 Then
.AbsolutePosition = .RecordCount - 5
Me.Bookmark = .Bookmark
End If
End With
 
T

Tony Toews [MVP]

Marshall Barton said:
You can use this code in the Load event:

With Me.RecordsetClone
If .RecordCount > 5 Then
.AbsolutePosition = .RecordCount - 5
Me.Bookmark = .Bookmark
End If
End With

AbsolutePosition?!?! I never knew about that one.

Thanks Marshall. My solution was getting rather complex and ugly. I
was getting rather embarrassed by it.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
T

Tony Toews [MVP]

Tony Toews said:
I'm getting not a valid bookmark on that line.

Never mind. My fault.

Mind you I'm still getting my wield bug but that's definitely a lot
simpler than I had.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
J

John Smith

Fair enough, I read 'show last X records' as meaning that was all that he
wanted to have on the form. Hope you manage to nail the bug!

John
##################################
Don't Print - Save trees
 
S

Steve S

The Load event of the form the subform is based on, or the load event of the
main form?

Thanks for your help.
 
M

Marshall Barton

Steve said:
The Load event of the form the subform is based on, or the load event of the
main form?

The form with the records you want to position.

I noticed that my code won't position to display the last N
records in the case where N < RecordCount < 2*N

I think this version should deal with that situation:

With Me.RecordsetClone
If .RecordCount > 5 Then
.MoveLast
Me.Bookmark = .Bookmark
.AbsolutePosition = .RecordCount - 5
Me.Bookmark = .Bookmark
End If
End With
 
S

Steve S

I tried your suggestion but there is no change in the way records are shown
in the subform. the exact coed is:
Private Sub Form_Load()

With Me.RecordsetClone
If .RecordCount > 12 Then
.MoveLast
.AbsolutePosition = .RecordCount - 12
Me.Bookmark = .Bookmark
End If
End With
End Sub

Maybe what I need is to have the scroll bar be positioned ate the bottom of
the window as each record is addes not at the top which is the default.

any suggestions?

appreciate your help
 
M

Marshall Barton

You're missing the Bookmark line after the MoveLast.

But that should only make a difference if the record source
has between 13 and 23 records.
 
?

.

dans l'article (e-mail address removed), Steve S à
(e-mail address removed) a écrit le 21/01/08 17:10 :
 

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