Base - datafields filled by code are not saved to table


Most fields on my form are entered by typing data in them or by selecting values from a dropdown or with a date-selector. A few fields however are filled by code.
I notice that my form only saves data that is entered manually, data that is entered by code is completely ignored. I have a save-button that performs the standard save-action. This button is normally greyed out and only turns black when the form detects that data have changed. This button too does not react to data that is not entered by hand.

Examples of entering data with code:

  • Upon selecting a value in a combobox A, the text-modified event triggers a script that writes “hooray” in textbox B.
  • Upon pressing a button, the execute-action event triggers a script that writes “button pressed” in textbox C

In both cases, the code is textbox.text = whatever. This does fill the textboxes, but the form does not detect this as data entry and subsequently does not save the data to the underlying data, even if the manually entered fields are saved.

How can I solve this?

Using LO with embedded database on Linux Mint 18.3 mate.


Do you have the form fields bound to database fields? (Iow: can you type into those fields and have that data stored?)

IIRC there is a boolean isModified property for the form fields, which may need to be set for each form element.

Yes, the fields are bound, so when I type in the values, they are saved. I haven’t found an isModified property (or something similar), I’ll keep looking, but I wanted this comment out fast.
Thanks for replying!

That boolean may be only a form property, not for each field. Sorry if I misled you.

The answer to this question may be helpful.

This one also looks promising.

Good luck!

I have had trouble with this behaviour. I can’t say I solved it, but I put in ‘commit’ statements, and the problem went away.

@keme: thanks, one of the links is very valuable to finally see all the properties and methods of an object! But IsModified is not the solution. In my first example, selecting a value in a combobox already set the form to modified and the fields were still not saved. Pansmanser’s answer worked for me too, and helped me find these related questions: How can I do form data entry via a macro? and Entering an integer value into a field in a Base form with a macro, all indeed suggesting the control.commit() after entering the data.