How to add LibreOffice Basic code to a form button?

I’m new to coding on LibreOffice Base - can someone please point me in the right direction?

I’ve create a form containing fields from my query and have added a button to the form.

I want to write and then execute a piece of LibreOffice Basic code when I press the button.

Anything will do at the moment - for example, a message could appear to say “You pressed me!”.

I can only see how to assign a pre-defined macro to a button so far (and even then I’m not sure I’m doing it right!)

Help! Please!

With your database open from the Menu - Tools > Macros > Organise Macros > LibreOffice Basic. Your database name will be at the bottom of the list on the left hand side. Click on the database name and select New from the right hand buttons. A popup will open with Title “New Module” with default name “Module1” - click OK. The Basic Editor will open with a new blank macro
Sub Main

End Sub

If you enter between these lines as below

Sum Main

MsgBox “You pressed Me!”

End Sub

Attach this Macro to the button.

To Edit or add new Macros use the menu route to the document Macros.

Follow the screenshot’s arrows.

If my answer helped you, vote it with :heavy_check_mark:
and with ∧ (here on the left)