How do I let Base jump to the last record of a table in a form?

Hello,

I am using a database form displaying a table to enter data. When I open that form it takes a second until it’s opened and then the first record is selected (the oldest entry).

I would absolutely love it to jump automatically to the LAST line (the newest record) instead!

The way it is now, I always have to click the “jump to last entry” icon…

Thank you for any help!

If you just want to move to the last record, without moving to the insert record (the one after the last record), then hook this to Form’s When Loading event:

Option Explicit

Private Sub WhenLoadingNew(oEvent As Object)
   REM Clone allows record motion independent of record updating

   Dim oForm   	  As Object :oForm		= oEvent.Source
   Dim oDoc		  As Object :oDoc		= ThisComponent
   oDoc.lockControllers
       oForm.moveToInsertRow  ' Pushes windows down to allow this to easily show later'
       oForm.Last
   oDoc.unlockControllers
End Sub

@EasyTrieve,

Tried replacing my routine with yours. I get nothing. Just opens on first record.

@Ratslinger, Sorry, I forgot to extract the 2’nd half w/ the moveToInsertRow, then Last. Now it should work.

Yeah, it works now. More lines of code but doesn’t need to set fetch size.

Just a note - only need Last or moveToInsertRow. Not both, only one or the other.

@Ratslinger, also chopped out the clone line and it still works. Then added comment for the reason moveToInsertRow is needed. (For data sets larger than one page.)

Interesting, if you leave in this line:

Dim oRS_clone  As Object :oRS_clone  = oForm.createResultSet() : oRS_clone.Last()

you don’t need both Last and moveToInsertRow. Remove the line and you need both.

Thanks for your comments and help! I will try these out asap. Just discovered these today because I had not been notified. Sorry for incorrectly posting this as an “answer” in the first place. :wink:

Thank you. I’ve been trying to find out how to do this for quite a while.

Hello,

If you always want to enter new records only, this is a property of the form.

If you also want existing records displayed, you need to use a macro:

Sub SetFetch
	oForm2 = ThisComponent.Drawpage.Forms.getByName("YOUR_INTERNAL_FORM_NAME")
  REM set this to something higher than existing # of records
    oForm2.FetchSize = 5000
    oForm2.Reload()
    oForm2.last
End Sub

Set the Open Document event of the form to this macro.