Hello,
Am not fond of this process. Can be problematic for many reasons but will present code used. Also concerning presenting code to those who do not know at least the general approach, maintenance in the future with be a problem.
First here is code used:
option explicit
Global iQuantSave as Integer
Global sSavePerson as String
Sub savePerson(oEvent)
Rem Check if Form is in Edit mode - Exit if true
If thisComponent.CurrentController.isFormDesignMode Then Exit Sub
Rem Save entred name
sSavePerson=Inputbox("Entee Name:")
End Sub
Sub saveQuant(oEvent)
Dim oColumns As Object
Dim oQuant As Object
Rem Save quantity every time different record is selected
oColumns = oEvent.Source.getColumns()
oQuant = oColumns.getByName("QUANTIDADE")
iQuantSave = oQuant.Value
End Sub
Sub updateFields(oEvent)
Dim aDate As New com.sun.star.util.Date
Dim oColumns As Object
Dim oQuant As Object
Dim oATUAL As Object
Dim oRESPON As Object
Dim iValue As Integer
Rem Check if Form event
If NOT oEvent.Source.supportsService ("com.sun.star.form.component.Form") Then Exit Sub
Rem Check if Update
If oEvent.Action = 2 then
oColumns = oEvent.Source.getColumns()
oQuant = oColumns.getByName("QUANTIDADE")
iValue = oQuant.Value
Rem Verify value has actually changed
If iValue <> iQuantSave Then
oATUAL = oColumns.getByName("ATUALIZACAO")
oRESPON = oColumns.getByName("RESPONSAVEL")
aDate.Day = DAY(NOW())
aDate.Month = Month(NOW())
aDate.Year = YEAR(NOW())
Rem Set Current date
oATUAL.Value = aDate
Rem Set Name entered
oRESPON.Value = sSavePerson
End if
End if
End sub
Only three routines. savePerson
is attached to the OpenDocument
event of the form. It is to retrieve the name.
saveQuant
is to be attached to the After record change
event of the internal form (MainForm). It retains the original quantity.
updateFields
is to be attached to the Before record action
event of the internal form (MainForm). It is the main routine which verifies the data is actually different and it is an update and not a new or deleted record.
Edit 2020-08-19:
Posting your sample with added code. Note that the code you had on Base opening (believe to hide main form) is dis-connected. It caused me problems. The added code is in frm_Abrir
. Also, you will probably want to do further checking on the user inputting their name. Currently the code does no checking.
Sample — AutoUpdateFields.odb