Thread: FoxPro Some General Questions/Display the last page of the grid when the form instantiates

Display the last page of the grid when the form instantiates
Display the last page of the grid when the form instantiates

*** Display the last page of the grid when the form instantiates
IF DODEFAULT()
  WITH Thisform.MyGrid
    *** Calculate the maximum number of rows per grid page
    lnMaxRows = INT( ( .Height - .HeaderHeight - ;
           IIF( INLIST( .ScrollBars, 1, 3 ), SYSMETRIC( 8 ), 0 ) ) / .RowHeight )
    GO BOTTOM IN ( .RecordSource )
    lnRecNo = RECNO( .RecordSource )
    *** Go to the record that should be in the first row of the last page
    IF lnMaxRows < RECCOUNT( .RecordSource )
      SKIP -( lnMaxRows - 1 ) IN ( .RecordSource )
    ELSE
      GO TOP IN ( .RecordSource )
    ENDIF   
    .SetFocus()
    IF .RelativeRow < 1
      *** Make sure it is the first relative row
      DO WHILE .RelativeRow # 1
        .DoScroll( 0 )
      ENDDO   
    ELSE
      DO WHILE .RelativeRow # 1
        .DoScroll( 1 )
      ENDDO  
    ENDIF
    *!* Now go back to the last record in the grid
    GO lnRecNo IN ( .RecordSource )
    .SetFocus()
  ENDWITH
ENDIF