How to automate database startup to open a form

I have a database that I need to open on a certain form. Whenever I do this, it takes a sequence of 7 mouse clicks to get me where I want to go. I would like to have an easy way that a user can do this in one click when I’m not there.

Would this be best to do with some kind of macro, or are there command line parameters I can use in a shell script?

LibreOffice 6.4.7.2
Ubuntu 20.04.6

You listed two options that seem suitable to you. In fact, the code for the first option has been around for a very long time and still works.

Sub openDefaultForm( )
Const MAIN_FORM_NAME = "YourMaimFormName"
Dim ObjTypeWhat As Variant 
Dim oDoc As Variant 
	ObjTypeWhat = com.sun.star.sdb.application.DatabaseObject.FORM
	If ThisDatabaseDocument.FormDocuments.hasbyname(MAIN_FORM_NAME) Then 
		ThisDataBaseDocument.CurrentController.Connect() 
		oDoc = ThisDatabaseDocument.CurrentController.loadComponent(ObjTypeWhat, MAIN_FORM_NAME, FALSE) 
		setVisibleMainWindow(False)
	Else
		MsgBox "Something happened to the " & MAIN_FORM_NAME & " form!"+ chr(10)+"You deleted? Or renamed?" , 48, "Form not found"
	End if
End Sub

Sub setVisibleMainWindow(bVisible As Boolean)
	ThisDataBaseDocument.getCurrentController().getFrame().getContainerWindow().setVisible(bVisible)
End Sub

Sub beforeClose(oEvent As Variant)
	setVisibleMainWindow(True)
End Sub

I’m not sure that the second option can be implemented. Is it possible that the same macro will be called on the command line?

There is actually another option and it is very popular. @Villeroy came up with a script that will split your project into separate forms and the database itself. The user does not need to make seven clicks - the user will simply open the desired Writer document (the desired form) and start working.
Also see here

There is an option to call a macro via command-line and I don’t see a reason why it should not work with Base. (But I never tried.)
.
I would not recommend this, because a shell script may call Base, but it will not be called, if a user double-click on the .odb. So one needs to modify OS- or desktop-starters to include parameters for this, wich may be tedious and not easily transferred to other users.

1 Like