Save Record While in Form With Macro Code

LO 7.4 Linux Mint 20 jdbc:MySql 8

I have a Form that requires some information filled in at the top of the Form so it can run a SQL Query to auto fill in information at the bottom of the form. Specifically, it needs the record’s ID which I set in a table column called ‘id’ (autofield, primary key). I need code that will save the record. After searching here I found the following code that was recommended in FirebirdCloseSaveMacro. I used that code as follows but it does nothing and doesn’t throw an error when I call the sub in the form. If I fill in the required fields first then click on the Save icon in Navigator Control everything gets filled in properly, so the rest of my form code is working, just need to force a record save to automate.

I have tried uno:Save, uno:RecSave and tried adding uno:Refresh and uno:RecRefresh, no joy.

Sub SaveRecord
    Dim dispatcher
    Dim oForm As Object
    Dim oDocument As Object
    Dim oParent As Object
    oForm  = ThisComponent.DrawPage.getForms().getByName("MainForm")
    oDocument = ThisComponent.Parent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dim args1(0) as new com.sun.star.beans.PropertyValue
    args1(0).Value = 0
    dispatcher.executeDispatch(oDocument, ".uno:Save", "", 0, args1())
    'dispatcher.executeDispatch(oDocument, ".uno:Refresh", "", 0, args1())
End Sub

@skyking52
.
You may have missed an important item of information in my response on the post you got the code from:

The main issue with using Firebird is the need to perform a Save or changes will be lost. This can be done using ‘dispatcher’. Then a matter of closing Base.

This post was about closing Base and the need to save all changes made during the session for Firebird. Most other databases do not need to do this with Base.
.
I point this out to note there are many finer points you need to be aware of when copying code. It is also why oDocument uses Parent to obtain the proper object - The main Base screen and not the form.
.
You may want to see this post → ThisDatabaseDocument vs ThisComponent?

Ah, OK - got it - I see that now. Layers inside layers of complexities (and sometimes surprises).

First solution with dispatcher:

SUB SaveRecord
 DIM oDocument AS OBJECT
 DIM oDispatcher AS OBJECT
 DIM Array()
 oDocument = ThisComponent.CurrentController.Frame
 oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
 oDispatcher.executeDispatch(oDocument, ".uno:RecSave", "", 0, Array())
END SUB

With .uno:Save you try to save the document, not the data in the form, which is in part of the document.
This macro should be started in the form …
Second solution directly in the form:

Sub SaveRecord
    Dim oForm As Object
    oForm  = ThisComponent.DrawPage.getForms().getByName("MainForm")
    IF oForm.isNew THEN
        oForm.insertRow()
    ELSE
        oForm.updateRow()
    END IF
End Sub

This could be started from another form in the same form document.

Thanks for that - really simple using insertRow(). I had tried that before but I think I had it in the wrong place. Finding the right spot (after setting up some required field values) now works as expected.