I do something similar on one of my apps. I implemented a classic table/subform pattern: I have First/Prev/Next/Last buttons that move the record on a table and then I have a form that shows all of the fields in the selected record. No temp state variables or other plumping needed. This also takes into account if you have any filters applied.
// js_SourceMovePrev
if (tblSource.selectedRow.index > 0) {
tblSource.selectRow(tblSource.selectedRow.index - 1)
}
// js_SourceMoveNext
if (tblSource.selectedRow.index < (tblSource.displayedData.length - 1)) {
tblSource.selectRow(tblSource.selectedRow.index + 1)
}
// js_SourceMoveFirst
if (tblSource.selectedRow.index > 0 ) {
tblSource.selectRow(0)
}
// js_SourceMoveLast
if (tblSource.selectedRow.index < tblSource.displayedData.length-1 ) {
tblSource.selectRow(tblSource.displayedData.length-1)
}