How can you check to make sure a form is fully loaded before running a macro?

I’m having an issue with the default save macro on libre base. It will run when a form is not fully loaded causing an “object variable not set” error.

The original save macro code was:
Sub Save
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)
dispatcher.executeDispatch(document, “.uno:RecSave”, “”, 0, Array())
End Sub

Then I tried to add validation to make sure the form loaded before running the macro but it’s not working. The macro will still run when the form is not loaded:
Sub Save
dim document as object
dim dispatcher as object
dim Loaded as Boolean
Loaded = True
dim oController
oController = ThisDatabaseDocument.CurrentController

if( Not oController.isConnected() ) Then
oController.connect()
Else
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)
dispatcher.executeDispatch(document, “.uno:RecSave”, “”, 0, Array())
End if
End Sub

Please help.

Hello,

Would help if you explained what you are doing.

What is triggering it?

Normally when you run a macro when opening a form the macro is attached to an event such as View Created.

The save macro is being referenced by another macro. I have a table control in my form and it has a combo box for the first column. Since I set it to trigger when the combo box loses focus, it always triggers on load by accident. Anyway, after I read your replies, I got an idea on how to fix this issue. I just added an invisible box and I have it update after my onload macro completes. The table control macro checks the invisible box to see if the form is loaded. If it isn’t, it won’t trigger. That fixed the issue.

Seems more like a bandage. May try to duplicate this later. Most likely a way to detect & bypass this load condition.
.
Edit 2022-01-07:
.
Having difficult time duplicating your situation. If you would like to actually solve the problem, please post a sample which demonstrates the problem.