Macro that performs the save function as the button/icon Save Record

I have a form with a few subforms and have not been able to find a macro that will save all the data entered or changed in the forms like what the Save Record button/icon does.
Does code exist that does the same thing as the Save Record button/icon that can be executed from a button?

For all this: Have a look at Base Guide 7.3

Robert,

I appreciate all your help, but referring me a 500+ page document doesn’t help.
I have quite a bit of documentation on LibreOffice and refer to it often, and am constantly learning - learning LibreBase is a long haul project unlike FoxPro, where I have years of experience.
Could you kindly point me to the sections and/or pages or examples in this massive document that are applicable.
Once again, thanks,
Erik

To your auestion: Yes.
.
For you problem:

Wonderer,
Got it. I used the predefined Save Record action as described, but the button only becomes active when I make a change to the parent form. My form has two subforms. When I make a change to either of the subforms, the button remains gray and not functional.
How do I make the button visible at all times (or once a change has been made to the parent form or a subform?
Thanks.

The button show if there is anything to save. The button is positioned in main form. It will save data of main form, not of sub form.
You could position a button in every subform. Navigation bar will do it for you.
If you are looking for code to save a form: Page 406 in Base Guide.
So you could create a button, which could save a form and a subform. But you have to prove if there is anything inside a row before you try to save it. A mainform could be saved without problems. But a new row in mainform doesn’t offer any content in subform. So saving both forms will lead to an error in you macro code.

Robert,

You are correct. Save Record action is form/subform specific and would required three Save Record buttons - one for my form and its two subforms. The Save Record button in the footer toolbar, though, works regardless of the number of subforms in the form. This is the functionality I would like to put in a button. And yes, I know the button would only work if there was a change to the data in a form and/or subform field.

Based on your recommendation, I downloaded the 7.3 BaseGuide to complement my other LibreBase docs. Unfortunately when I go to page 406, I find “Testing and Changing Controls”, and nothing about saving a record.
Thanks, Erik

Robert,

I was incorrect. They discuss updating rows on page 406. I was looking for save record. I guess they are the same thing when you think about it.
Question - the object oForm… is used. I assume I must define oForm. And if I do, I assume this will point to only my form or one of its subforms, not all of them collectively. If this is the case do I repeat the code for each of the three “forms”?
Thanks, Erik

The navigationbar at the footer will show the content for a form or a subform. Not for both together. The connection to the special form will be changed when you move to the subform. So it is the same as a simple “Save”-button in every form an subform. The function behind this control is .uno:RecSave - also in the navigationbar at the footer.

Give this a try. It works for me:

REM ***** Use With Macros Below to Save Forms From Pushbuttons *****
Sub FormSave(sSave)
Dim ObjName As String
Dim Document As Object
Dim Dispatcher as object
ObjName = sSave
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)
dispatcher.executeDispatch(Document, “.uno:RecSave”, “”, 0, Array())
End Sub

SUB SaveFrm_Add 'Set your Button’s “Execute Action” to this
FormSave(“Frm_Add”)
END SUB

Why do you add a macro for a function, which is implemented in the button? You could choose the saving for the button - its the same .uno:RecSave which will run.

It keeps your code clean, and makes it easier to use in multiple locations. If you only have one form that saves, then yes, you are correct. This would be redundant. :laughing:

Moojybar,

It looks like a way to save the form with the subforms.
I’ll give it a try.
Thanks,
Erik

Moojybar,

I tried the code you provided and got a syntax error at the line:
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)
where “createUnoService(” was highlighted.

Any idea on what the problem is?

Below is the code you recommended that I pasted into my macros and executed from a form button.

Also, for some reason the SUB SaveFrm_Add routine doesn’t appear in the list of macros to select in the button Execute control. I moved the code before the Sub FormSave routine and it found it.

Thanks,
Erik

Sub FormSave(sSave)
Dim ObjName As String
Dim Document As Object
Dim Dispatcher as object
ObjName = sSave
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)
dispatcher.executeDispatch(Document, “.uno:RecSave”, “”, 0, Array())
End Sub

SUB SaveFrm_Add
FormSave(“Frm_Add”)
END Sub

Hey @nebergall,

It took me a year or two, but I found the cause. Of course, I feel like a fool. What I gave you was incomplete. Try this as your Sub:

SUB SaveFrm_Add(oEvent AS OBJECT) ’ I forgot half this line. Something has to be set as object.
FormSave(“Frm_Add”) ’ Be sure to set Frm_Add to the name of your form.
END Sub

You have my apologies. I’m sorry for the lost time. I’m no expert. This is just something that I had pieced together from different types of save code that I had found. It works for me, so I hoped that it would work for others. It works in forms and subforms. However, I’m struggling to get it to work in a subform of a subform. If someone happens across this and has any ideas, I’d love to hear them.