Moving to last record in a subform.

R

Rob W

Greetings,

On my main form after the last combo box is populated I display my subform,
and I want to move the last record.

After searching the web I found the following code and tried it, Even though
the subform is populated (subform is based on a query matching values on
main form)
it never prints the debug message.

If i REMOVE the if statement i.e. not checking the number of records within
the subform it throws an error "3021 : No current record" this happens once
then the program can continue to run and display rows in the subform but
still never moving to the last row.

The name of the subform is correct using the value in NAME and not SOURCE
OBJECT.

Can anyone please assist/offer advice?

Thanks
Rob

Me.qryStudentsResultsDeliverysubform1.Enabled = True
Me.qryStudentsResultsDeliverysubform1.Visible = True

With Me.qryStudentsResultsDeliverysubform1.Form.RecordsetClone
' make sure there is at least one record
If Not .EOF And .BOF Then
MsgBox "Im in here"
Me.qryStudentsResultsDeliverysubform1.Form.RecordsetClone.MoveLast
End If
End With

Me.qryStudentsResultsDeliverysubform1.SetFocus

End Sub
 
A

Allen Browne

Set the Bookmark of the form to match the bookmark of the last record in the
clone set:

With Me.qryStudentsResultsDeliverysubform1.Form.RecordsetClone
If Not .EOF And .BOF Then
.MoveLast
Me.qryStudentsResultsDeliverysubform1.Form.Bookmark = .Bookmark
End If
End With
 
R

Rob W

I assume EOF and BOF are Beginning and End markers.

The subform is populated with 1 or more rows but the code in the statement
is never getting executed (tested with debug messages).
 
D

Douglas J. Steele

I think Allen forgot to correct the typo in your original code. Try:

If Not .EOF And Not .BOF Then
 
R

Rob W

I've been testing, the sub form though populated with rows I believe has a
recordcount of 0.

Very confusing ...
 
A

Allen Browne

It should not have a RecordCount of zero if there are records.

It might depend on what event you are using to test this. For example, when
you move records in the main form, it has to reload the subform. So in the
main form's Current event, the subform might not be loaded yet.
 
R

Rob W

It was a requery issue in the end.

Rob

Allen Browne said:
It should not have a RecordCount of zero if there are records.

It might depend on what event you are using to test this. For example,
when you move records in the main form, it has to reload the subform. So
in the main form's Current event, the subform might not be loaded yet.
 

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