Problem with subform to last record

N

Nick

I have a subform that by it self will open to the last record using Private
Sub Form_Load() DoCmd.GoToRecord Record:=acLast but when it is attached to a
parent form it will not.
 
D

Dirk Goldgar

Nick said:
I have a subform that by it self will open to the last record using Private
Sub Form_Load() DoCmd.GoToRecord Record:=acLast but when it is attached to
a
parent form it will not.


The subform loads before the parent form. Then, if it's linked to the main
form, when a new record becomes current on the the main form, the subform
will be filtered to match that record, and won't be at the last record.

You might try putting code in the main form's Current event to move the
subform to its last record. Something like this:

'----- start of example "air" code -----
Private Sub Form_Current()

With Me.Subform1.Form.Recordset
If .RecordCount <> 0 Then .MoveLast
End With

End Sub
'----- end of example code -----

Replace "Subform1" with the name of the subform control on your main form.
Note that the name of the subform control may not necessarily be the same as
the name of the form it displays.
 
D

DocBrown

This works good form me also. but I have one more question.

The subform displays say 10 records. How can I make that last record display
at the bottom of the form so that 10 full records are displayed on the
subform?

Thanks,
John
 
D

Dirk Goldgar

DocBrown said:
This works good form me also. but I have one more question.

The subform displays say 10 records. How can I make that last record
display
at the bottom of the form so that 10 full records are displayed on the
subform?


If you know how many records the subform will display, then you can
hard-code that into a modification of the code that I previously gave you.
I've only tested this lightly, you understand, but this seems to work for a
subform that displays 10 records at a time:

'----- start of code -----
Private Sub Form_Current()

With Me.Subform1.Form.Recordset
If .RecordCount <> 0 Then
.MoveLast
If .RecordCount > 10 hen
.Move -10
.MoveLast
End If
End If
End With

End Sub

'----- end of code -----
 
Top