goto last records on open

On the event on load form, I like to jump to the last record or a new one. Is there an existing function, macro that you can use easily?


You can set a form to allow entry of new records only which then always displays a new record.

Open your form in edit mode. On the Form Design toolbar, there is an icon for Form Navigator, click that. Right mouse click your form name and select Properties. On the Data tab, set Add data only to Yes. Save the changes.

If you want to have all records available but still be positioned on a new record, you need to use a small macro:

Sub GoToNewRecord()
	Dim oForm As Object
Rem Get the internal form
	oForm = ThisComponent.Drawpage.Forms.getByName("YOUR_INTERNAL_FORM_NAME")
Rem Set records to be loaded
	oForm.FetchSize = 5000
Rem Move to insert row record
End Sub

You will need to supply your internal form name (most likely ‘MainForm’). This routine is attached to the When loading event of the internal form. For more information on LO macros see the documentation → LibreOffice Base Handbook. Look in Chapter 9 - Macros.

I tried using the macro above to solve the problem I described here:

When I open the form I get this message:

BASIC runtime error.
An exception occurred
Message: .

It takes me to the macro editor, with the following line highlighted:

oForm = ThisComponent.Drawpage.Forms.getByName(MainForm)

The form I am working on has the internal name “MainForm” (on the “general” tab of its property sheet).
Any idea what’s wrong?

The name of the form must be surrounded by quotes. The code displayed does not show this.

Yes, adding the quotes fixes it. Thank you. On one of my tables that has over 3500 records, the form takes a few seconds to load, as it finds its way to the last record I suppose.