SAVE isn't saving the updated field (Macro Issue)

So here is the Macro…That is working!!! But fail to SAVE

After running the following macro, I can see the correct % at the form (MsgBox & Field). The field that is receiving the data back is “txtCal_DownPay_P” only part that is missing is even though the information is updated form’s SAVE button still gray and I can’t save it. The only way to save it is…If I go to that field and rewrite the calculated info than SAVE wakes up!! How to fix it, please!!!

Sub Call_Calculator (Event as Object)
		dim Form as Object
		dim tempP_SalesPrice as double  
		dim tempDownPay as double
		dim tempDownPay_P as double
				
		Form = Event.Source.Model.Parent
		
		tempP_SalesPrice = Form.getByName("txtP_SalesPrice").currentvalue

		tempDownPay = Form.getByName("txtCal_DownPay").currentvalue

		tempDownPay_P = tempDownPay / tempP_SalesPrice
		
		Form.getByName("txtCal_DownPay_P").text = tempDownPay_P
						
		MsgBox("Down payment % is "& tempDownPay_P)

End Sub

Hello,

Haven’t time to test currently but if needed will do so after a good night’s sleep.

You move the data into the control but that is all. You need to commit() it.

Try this. Change this line:

Form.getByName("txtCal_DownPay_P").text = tempDownPay_P

to:

Dim oField as Object
oField = Form.getByName("txtCal_DownPay_P")
oField.text =  tempDownPay_P
oField.commit()

Fairly certain that’s the code. Also not sure why you are using a text box and text instead of a numeric control and setting via .value?

Edit 2020-03-03:

Please, always include OS, specific LO version and database used (seems this is a split HSQLDB but not certain of version). Should not need to trace through old questions and things can change rapidly.

Don’t know what problem you are having. Used your code (changed control names to what I have) and used my modification from above. Worked first time!

Note that in the sample I have removed the enabled property for the control since it is a calculation.

Sample ------ FieldCalc.odb

Hi Ratslinger:
I just tried your suggestion and It didn’t solve the issue.
It did produce the same result as I had before. Correct updated answer at the form’s field but failed to save.

@MQ-818,

Please see edited answer

Note: field is calculated when you exit the DownPay field.

Ratslinger:

FieldCalc.odb
Works …Thanks for your kind help.

Monjur

Added the following line and all started to work.

oForm.Columns.GetByName( “Cal_DownPay_P” ).updatedouble(tempDownPay_P,3)

here Cal_DownPay_P is the Field Name in the Table And tempDownPay_P is a temp field in the macro

Thank you all