Base Forms Events - Run Macro After Load

Running LO 6.4.7 on Linux Mint 20. Have an older app that will automatically remove all Design Toolbars and leave just the Menu Bar. This is done with a Macro. Every one of the 6 Forms in that app run the Macro on open, however there is no reference to the Macro in any Form Events. This is making me crazy after wasting several hours looking for an event that auto launches the Macro and can’t find any. There is a Macro to load the Menu Form set in Open Document.
I have created a new app and it is using the same Macros. I can auto launch the Menu app in Open Document, but the Macro to remove the toolbars after Form open never launches using any Form Events.

Macro to Hide:
Sub HideAllMenuToolbars
’ If Design mode, just exit the routine and display standard menu and toolbars’
xCurrentController = thisComponent.CurrentController
If xCurrentController.isFormDesignMode Then
Exit Sub
End If
xLayoutManager = thisComponent.CurrentController.Frame.LayoutManager
xLayoutManager.visible = false
End Sub

Macros to Open Menu Form and Minimize LO Base Form:
Sub OpenFormMain
MinBaseWin
ThisDatabaseDocument.CurrentController.connect("","")
form_container = ThisDatabaseDocument.FormDocuments.getByName(“Main”).open
End Sub

Sub MinBaseWin
oController = ThisComponent.getCurrentController()
oFrame = oController.getFrame()
oContainerWindow = oFrame.ContainerWindow
oContainerWindow.isMinimized = True
End Sub

  1. How do I get a Form to Launch HideAllMenuToolbars after Load?
  2. Where could the old app be launching HideAllMenuToolbars on every Form Open/Load when I can’t find it referenced in any Form Events?

New app will be used by others for Data Entry so I need to have it looking somewhat polished.

Thanks for any insights or suggestions.

Hello,
Using your code (except for incorrect apostrophe), had no problem with using Event Open Document:

Screenshot at 2022-11-01 14-36-44

Here is the Base file:
OpenNoToolbars.odb (13.0 KB)
.

Could be on the internal form event of When Loading.
.
Edit:

Also see this possibly related post →

Yes the code works fine to open the Menu Form on Open Document Event. It’s the load Macro after Form Open that I can’t figure out, and can’t find reference to the HideAllMenuToolbars Macro anywhere in the old app. Will look at the Macro Security issue. Thanks.

What am I missing? Only see these questions:

Just wondering if there’s an alternative event or method to load my macro after the form is loaded since the ‘When Loading’ Event doesn’t fire off. I know VBA has a Form Load event that runs macros after the form has loaded and my Macro needs the Form loaded to reference correctly.
I wish I could find what is firing off my macro in the old app but I’ve looked everywhere and no joy. Is there a debug or tracing mode I could run to track down the macro launch in the old app? I built it a couple years ago using an older version of LO.

Just did an upgrade to 7.4.2, no change in form load events :>(

Usually I would use View Created
.
For your issues, could you provide a redacted sample? Respectfully, not certain you have looked everywhere or it seems you would have found it.

BTW I tend to ignore anything noting VBA or MS.

LOL…been on Linux for 25 yrs myself - avoid anything MicroSloth…LOL

Here is my old app…oh, won’t let me upload a .zip

@skyking52
Weird thing here is .zip is not allowed. Change to .odt and note this is to be changed to .zip after downloading.

Uploaded to my server so you can download from there (5.2Mb too big to upload)
Knife App zip

@skyking52
Yeah, got it after first correction.
Wasn’t hard to find. Only looked a opening form → Main. Many of the buttons have an Event When receiving focus pointing to the macro HideAllMenuToolbars
Is that what you are looking for?
.
Edit:
In the form Steel the event is on the TextBox for Type!
.
Seems to be around quite a bit.

@skyking52
Just FYI, the file was too big mostly because of HSQLDB jar file. In driver folder & probably in the .odb file also.

Well DUH…{palm slap to forehead}

Didn’t even think to check first form object for focus event…

You da man!

Guess I’ll use the same method in new app since it works…

Thanks again.

One more thing - getting this error popup now on LO open after upgrade

Screenshot from 2022-11-01 21-01-30

Sorry but I use the TDF version (Download LibreOffice | LibreOffice - Free Office Suite - Based on OpenOffice - Compatible with Microsoft) and there are no issues on opening:


Main Base screen opens to task bar.

I followed the instructions to upgrade linux version adding the ppd in apt then did apt install.
Error doesn’t seem to have any effect on LO operation so far.
UPDATE: Error has now disappeared when LO starts so it self-corrected (cool)

Also, is there any way to make the window that the form is open in to match the form’s page style size? If I resize the window for the main form, all subsequent windows keep that size and forms don’t fit.

Two things. Your images look like a Zoom factor issue! Resize forms macro:

Sub ResizeX(iWidth,iHeight,Optional iXPos,Optional iYPos) As Integer
'Set the width & height of the form to be displayed
'Used because the tool bars are turned off elsewhere
'This cleans up the dead space
	Dim vRect as Object
	If IsNull(thisComponent.currentController.Frame) then exit sub
	vRect = thisComponent.currentController.Frame.ContainerWindow.PosSize
    Wait 200
    If IsMissing(iXPos) Then iXPos=vRect.X
    If IsMissing(iYPos) Then iYPos=vRect.Y
	thisComponent.currentController.Frame.ContainerWindow.setPosSize(iXPos, iYPos, iWidth, iHeight, 15)
    Wait 200
	thisComponent.currentController.Frame.ContainerWindow.setPosSize(iXPos, iYPos, iWidth, iHeight, 15)
End Sub

.
Also had no problem with your code working on the Open Document when I used the macro I have been using for years:

Sub OpenFormSteel
'	form_container = ThisDatabaseDocument.FormDocuments.getByName("steel").open
ObjName = "steel"
	ObjTypeWhat = com.sun.star.sdb.application.DatabaseObject.FORM
	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 "Error! Wrong form name used. "+chr(10)+"Form Name = " & ObjName
	End if

End Sub

Note this is Q&D. Code I use passes the form name to this via parameter. Hav posted this on site some time in the distant past.

Edit:
Even more simple. Changed this:

form_container = ThisDatabaseDocument.FormDocuments.getByName("steel").open

to:

ThisDatabaseDocument.FormDocuments.getByName("steel").open

and the Open Document event worked.

Thanks for all of that - Form Resize Macro works fantastically!
My OpenMainForm macro has always opened with the Open Document global event, that isn’t an issue. After putting the HideToolbar macro in the first focused form object, all forms are now opening with toolbars removed. Nice work-around to not having a true OnFormLoaded event. Plus I added the Resize to each separate macro with HideToolbar so on launch each Form gets resized and positioned and toolbars removed. Brilliant!