Launch a Form on Base startup

My system info:

Version: 7.5.5.2 / LibreOffice Community
Build: caf8fe7424262805f223b9a233
Environment: CPU Threads: 4;OS: Windows 10.0 Build 19405
User Interface: UI render: Skia/Raster; VCL:win
Locale: en.GB (en_GB); UI: en-GB
Misc Calc: threaded
Database HSQLDB Embedded

Like many other people, I’m sure, I want Base to launch a particular form when I open the db. It seems that there’s no built-in way to do this (e.g. go to settings/general/launch form at startup/“name of form”).

I’ve found a thread, on a different forum, which gives macro code for doing this.

Is that the only option then - a macro? Thanks.

Open the form.
Save the form as a stand-alone Writer document.
Close the form.
Open the saved document.
Reconnect all logial forms and subforms, either by registered name or by file path of the odb.
Make the document read-only, either on file system level or via File>Properties>Security.

Now you can open the form without the database document, and you can use ordinary hyperlinks to open other forms.

My “FreeHSQL” macro includes a “FreeForms” macro which performs the above steps for all forms in a database document.

2 Likes

Thanks for this. I’m afraid that using your macro will be way beyond me. In fact your advice about saving the form and reconnecting all logical forms and subforms is also a mystery.

Shouldn’t this be simpler? Thanks again.

Edit: Here is the code from ‘neptuneuk’ on that other forum. I’m thinking of trying this.

Sub Menu_Main( )
Dim ObjTypeWhat
Dim ObjName As String
ObjTypeWhat = com.sun.star.sdb.application.DatabaseObject.FORM
ObjName = “Menu_Main” 'The name of the form you want to open at Base start-up, this needs to exist.
If ThisDatabaseDocument.FormDocuments.hasbyname(ObjName) Then 'Check the form exists
ThisDataBaseDocument.CurrentController.Connect() 'If the form exists connect to the database
ThisDatabaseDocument.CurrentController.loadComponent(ObjTypeWhat, ObjName, FALSE) 'Open the form
Else
MsgBox “This is embarrassing, sorry, can’t find the requested form to open!”+chr(10)+"Form Name = " & ObjName + chr(10)+“Check the details.” , 48, “DS4A SBM encountered a problem!”
End if
End Sub

You will also need to do the following (assuming you only want to run this in a particular Base odb file (your current project)).
Tools → Customise->
Then assign the macro to the ‘Open Document’ event.
Save in - select the appropriate location (probably the current odb file is what you will want), this will only then run when that odb file is loaded.

Download the attached extension from the above linked topic.
menu:Tools>Extensions… [Add…] and add the downloaded extension.
Open your database document.
menu:Tools>Macros>Run Macro…
Navigate on the left side “My Macros” > FreeHSQLDB > FreeForms
Click “Main” on the right side and click [Run]

1 Like

Hmmm. OK, tried that. (I presume you really meant database document, not form). When I get to this bit “Navigate on the left side “My Macros” > FreeHSQLDB > FreeForms Click “Main” on the right side and click [Run]” I get the message:

“Free HSQLDB: No database document.
This tool works with database documents (*.odb) only.”

I saved the database Form as an .odt file. Was that wrong? Thanks.

Yes, I do mean the database document, indeed. The macro saves all the forms that are contained in the database document as stand-alone forms in the same directory as the database document. The error indicates that the active document was not a database document when you called the macro via Tools>Macros>Run…

1 Like

Ah. Sorry to be dense here but by ‘database document’ you mean the actual database (or perhaps to be accurate, the Base GUI)?

So I should have Base open (no Form, Query or Report open) and run the Macro at that point?

It simply exporrts all of the forms embedded in the database document without touching the existing embedded ones. Just delete the files you don’t need.

1 Like

OK, got that working. Thanks.

That saved the forms, but when I open them I get an error message.

A Scripting Framework error occurred while running the Basic script vnd.sun.star.script:Standard.Module3.Initform?-language=Basic&location=document.

Message: The following Basic script could not be found:
library: ‘Standard’
module: ‘Module3’
method: ‘InitForm’
location: ‘document’

Well, the error message tells it all. The form tries to call macros that used to be embedded in the database document. Now there is no more database document loaded. Just put your macros into a dedicated library under “My Macros”.