How do I go to the last record on a subform

  • Thread starter Thread starter Jon A
  • Start date Start date
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?
 
Hi
Jon


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


ORDER BY tbl_Items.DateEntered DESC;
 
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
 
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.
 
Back
Top