How is the macro call "prior to reset" working?

Hello,

I try to safe a value from a form into a table when a new data set is created in another table. For this the “prior to reset” call is exactly what I need. The call of the macro is working like I need it.
In most of the manuals you can read:

Prior to reset
The Prior to reset event occurs before a form is reset. Returning True approves the reset, returning False cancels the operation.
A form is reset if one of the following conditions is met:
1. The user presses an (HTML) button that is defined as a reset button.
2. A new and empty record is created in a form that is linked to a data source. For example, in the last record, the Next Record button may be pressed.

BUT…
the values in the form are already reset when the macro is called. Is the name “prior” wrong or am I too stupid to use it?

'###### This Sub is called when a form field is changed and working fine
Sub Form_Articole_Code
	DIM oDoc as Object
	Dim oFormular as Object
	Dim oArt as Object
	Dim oSac as Object
	Dim oCode as Object
	Dim Nummer as Long
	
	oDoc = thisComponent
	oFormular = oDoc.drawpage
	oArt = oFormular.forms.getByName("MainForm")
	oSac = oArt.getByName("SubFormSac")
	oCode = oArt.getByName("SubFormCodes")
	
	'Some Code in between

	oCode.reload
	Nummer = oCode.getLong(3) + 1
	oArt.updateLong(3, Nummer)
	oArt.updateRow()
	'###### here it is working but it creates problems 
        '###### when the user changes after values in the form again. 
        '###### Because of this I want to move the following 2 lines in the "prior to reset" Sub
        'write back Nr in Code table
	oCode.updateLong(3, Nummer)
	oCode.updateRow()
End Sub

'### The sub is called when the Main Form (oArt) is reset
Sub Form_Articole_PriorToReset
	DIM oDoc as Object
	Dim oFormular as Object
	Dim oArt as Object
	Dim oCode as Object
	Dim Nummer as Long
	
	oDoc = thisComponent
	oFormular = oDoc.drawpage
	oArt = oFormular.forms.getByName("MainForm")
	oCode = oArt.getByName("SubFormCodes")
	
        '### here the values are already deleted
	'write back Nr in Code table
        oCode.reload                                          'added for testing
        Nummer = oArt.getLong(3)
	oCode.updateLong(3, Nummer)
	oCode.updateRow()
End Sub

Thank you in advance for any help.

Which event do you use to execute the macro? Should be “Before record action” of the form.

:thinking:
Events - Prior to reset

I use “Prior to reset” because I want to do it only when a new record is created

I tested just now “Before record action”. This way it seems to still have the data in the form. But every time I change a record in the form the script is called twice.

If you could upload the problematic file and describe the sequence of actions that lead to the problem, then the path to the truth would be shorter.


By the way, UNO objects have slightly different names from UI ones.
Before record acrion => approveRowChange
Prior to reset => approveReset

Use a boolean function rather than a sub. If the function returns False, the reset or the record action won’t take place.
Some events are called from the form controller and from the form model. Test the caller and exit the function if it is the wrong one.

EDIT: simple test document demonstrating how “prior to reset” works and fails.
prior_to_reset.odt (22.2 KB)

Load the form at record 1, edit the box and push the reset button. Nothing is triggered.
Move to the new record. The macro is triggered, the answer to the Msgbox does not cancel the command.
Edit the string in the new record and push the reset button. Answer “No” to the Msgbox. You are still in editing mode, but the reset button is disabled.

https://bugs.documentfoundation.org/show_bug.cgi?id=167408

1 Like