Ask Your Question
0

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

asked 2018-01-27 20:10:32 +0200

Lovro gravatar image

updated 2018-01-30 17:06:00 +0200

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.

image description

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?

edit retag flag offensive close merge delete

Comments

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.

Ratslinger gravatar imageRatslinger ( 2018-01-27 22:02:10 +0200 )edit

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

Lovro gravatar imageLovro ( 2018-01-30 16:20:55 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-01-30 19:07:59 +0200

Ratslinger gravatar image

updated 2018-01-30 19:12:58 +0200

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?

edit flag offensive delete link more

Comments

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.

Ratslinger gravatar imageRatslinger ( 2018-01-30 22:39:36 +0200 )edit

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.

Lovro gravatar imageLovro ( 2018-01-31 09:58:43 +0200 )edit

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."

Lovro gravatar imageLovro ( 2018-01-31 15:53:47 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2018-01-31 16:43:50 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2018-01-31 17:19:10 +0200 )edit

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

Lovro gravatar imageLovro ( 2018-02-07 13:31:52 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2018-02-07 15:55:13 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-01-27 20:10:32 +0200

Seen: 205 times

Last updated: Jan 30 '18