Ask Your Question
0

goto last records on open

asked 2018-12-24 09:23:36 +0200

loruska gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-12-24 17:20:09 +0200

Ratslinger gravatar image

Hello,

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
    oForm.moveToInsertRow()
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.

edit flag offensive delete link more

Comments

I tried using the macro above to solve the problem I described here: https://ask.libreoffice.org/en/questi...

When I open the form I get this message:

BASIC runtime error. An exception occurred Type: com.sun.star.container.NoSuchElementException 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?

dougmn gravatar imagedougmn ( 2019-01-01 17:32:26 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2019-01-01 17:36:07 +0200 )edit

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.

dougmn gravatar imagedougmn ( 2019-01-01 23:24:56 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-12-24 09:23:36 +0200

Seen: 91 times

Last updated: Dec 24 '18