using basic to change form current record state to "not saved"

In Libreoffice base, I have one listbox control on a form which I use to have many to many relationship - I use it to select one or more workers which have been visited measuring station. Other controls on this form are bounded to data source of the form, but the listbox is not, since there is no automatism to achieve that. I populate all the data in listbox related table programmatically via basic.

I am just missing one final step - I want to trigger a macro for saving listbox data when current record is saved, current record is changed or form closed

I tried to use events “After records action” or “Before submitting”. It works when other data on form is changed. When only listbox contents are changed, macros do not trigger.

I tried to use isModified property of the form to change form state, so events are triggered.

set oForm = ThisComponent.DrawPage.Forms.GetByName("Obilasci")
' "obilasci" is name of the form with controls
oForm.IsModified = True

When trying to save form data, an error appears:
image description

How to make this work ? One workaround I can think of is to create a dummy database column which will be changed when listbox content is changed, but I could not get it to work either.

Update: i got it to work with this workaround, by updating the control underlying data, but I wonder could it be done without it? Why isModified property is R/W and not only Read?

Hello,

First there is no “visual” basic in LO - just call it basic. Your description is rather confusing as you state trying to save but also state ‘Event “After records action” is used’. Use of isModified probably has little to do with your problem. Code is needed and a much better description of exactly what is to be accomplished. A sample without personal/confidential info would be of help. Statements such as ‘property of form’ confuses; it is certain you have mult internal forms in use.

Hello, I tried to make my question more concise, I hope I succeded.

Hello,

Sorry but the updated information does not really clear up what is actually being done.

From what can be extracted from this question, the concern is the listbox. The data comes from basic code. It is not clear what this code does. May read another table & use this to fill list box? Is this where the data comes from? It seems you can modify the listbox somehow but want to trigger an isModified for a different form. Not logical. Why not, whatever your update is (not mentioned but must be some code), use a Changed or some other event for the listbox for this process? Also don’t understand why you need code to fill the listbox if the data is in a table. Should be able to do so without code.

Based upon your statements the error message is logical since there may be nothing on the form you set isModified on. Again can’t help much more without more info or the best solution would be a sample as previously stated. Your problem seems to be with the way the form is designed & how you want some processing to occur.

Also:

 i got it to work with this workaround, by updating the control underlying data, but I wonder could it be done without it?

Not clear as to what this means?

Another thought, possibly attaching to document event - Document/View is going to be closed. Just a guess. Don’t really understand what process you are attempting.

Hello, sorry again for not clearing things up.
Data for the listbox come from another table, different from the table for the form.
I think that UX is better with multiselect listbox than with subform, so I don’t want to use subform, although it is programmatically easier.

Subroutines write and read data from the listbox, triggered on events.

When only listbox content on already saved form is changed, “After record change event” used for saving does not trigger.

i got it to work with this workaround was meant on this workaround (in text):
“One workaround I can think of is to create a dummy database column which will be changed when listbox content is changed, but I could not get it to work either.”

Not much has changed here. As my answer guessed, the listbox is from a table. It should be filled & saved directly on a subform or another form, not through code. Again much info missing. Where do the added entries come from? Seems another unnecessary addition. Use a combo box instead. You can add entries directly. Until the FULL process procedure is supplied (step by step what is being done) and a sample, there is nothing more which can be offered. It’s a design problem.

Also have given you another option which was stated in first comment - to save the file when document closes.

Hello,
this option is only partial solution, as contents of the listbox should be updated to dedicated table (different from form underlying table) not only on form close, but also on record change. However, it should not be updated if record editing of the form is cancelled. Therefore, it is best to bind update to “After records action” event

As previously stated, can’t help any further until more info provided. Previous comments mention this. Certainly there would be a complete and easier solution with a sample.