How do I go to the last record on a subform

J

Jon A

I have an easy question but I am new and can't figure it out.

I have a main form and on it is a subform. The subform displays the
many record related to the one on the main form. The subform is set as
Single Form, which is what the users want. Whenever you go to a record
on the main form, the subform displays the first of the child records
related to that one on the main form. That's not what the users want
because the record they will always want to work with is the last
(most recent) record. That means they have to use the Navigation
buttons on the subform to go to the last record. They want me to
change it so that whenever the main form goes to a new main form
record the subform displays the last or latest of those records.

I have tried putting this in the subform event Form_Current:

DoCmd.GoToRecord , , acLast

However what happens is that the Main form jumps to the last of the
main form records and you can never get off of it. No matter what
button you click on the main form jumps to the last record and the
subform still displays the first record in that subset.

I'm confused. How do I do it?
 
T

Timbuck2

Hi
Jon


Place an OrderBy on the recordsource of the subform to Sort Descending on
the Date Entered


ORDER BY tbl_Items.DateEntered DESC;
 
M

Marshall Barton

Jon said:
I have a main form and on it is a subform. The subform displays the
many record related to the one on the main form. The subform is set as
Single Form, which is what the users want. Whenever you go to a record
on the main form, the subform displays the first of the child records
related to that one on the main form. That's not what the users want
because the record they will always want to work with is the last
(most recent) record. That means they have to use the Navigation
buttons on the subform to go to the last record. They want me to
change it so that whenever the main form goes to a new main form
record the subform displays the last or latest of those records.

I have tried putting this in the subform event Form_Current:

DoCmd.GoToRecord , , acLast

However what happens is that the Main form jumps to the last of the
main form records and you can never get off of it. No matter what
button you click on the main form jumps to the last record and the
subform still displays the first record in that subset.


Right! You definitely do not want to use the subform's
Current event to get the subform to go to a specific record.

Use the main form's Current event:

With Me.subformcontrolname.Form.RecordsetClone
If .Recount > 0 Then
.MoveLast
Me.subformcontrolname.Form.Bookmark = .Bookmark
End If
End With
 
J

Jon A

Thanks to both of you for the wonderful answers. They both work but do
things differently. I will see which one the users want.

Cheers.
 

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