Using GotoRecord with Subform

S

Stephen

I have been reading all sorts of forum on this topic and still cannot get
this thing to work:

I have a continuous subform that display 10 records in teh viewable area. I
am trying to create a command button ("Next Page") on the main form that
will advance the records on the subform so that it displays teh next set of
10 records (mimics a page-down effect).

I have the following code (not there is a field on the main form called
"lastrecord" which keeps track of which record position has teh curent
focus.

Option Compare Database
Option Explicit

Dim ORDERRECORDS As Integer ' number of records in the recordset
Dim RecordsToMove As Integer ' number of records to advance
Const FORMRECORDS = 10 ' ' the number of viewable records

Private Sub NextPage_Click()

Dim targetForm As Form
Set targetForm =
Forms!sfrmOrder!sfrmOrderSubformTicket!sfrmOrderSubformTicketDetail.Form
ORDERRECORDS = targetForm.Recordset.RecordCount
If ORDERRECORDS > FORMRECORDS Then
If ORDERRECORDS - Me.LastRecord > FORMRECORDS Then
RecordsToMove = Me.LastRecord + FORMRECORDS - 1
Me.LastRecord = Me.LastRecord + FORMRECORDS - 1
else
RecordsToMove = Me.LastRecord + FORMRECORDS
Me.LastRecord = Me.LastRecord + FORMRECORDS
End If
Me.sfrmOrderSubformTicketDetail.SetFocus

DoCmd.GoToRecord , , acNext, RecordsToMove
End If


When I run this code, I get the following error:
Runtime 2105: You can't go to the specified record.

Any help?
 
B

Bryan Reich [MSFT]

I think you want the 3rd argument to GoToRecord to be acGoTo and not acNext
since your calculations for your RecordsToMove value aren't the number of
records to move but are instead the absolute record number. That's just the
first thing that stands out to me. I'm not sure if that will solve
everything.
 

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