Error in .Model

Hi.
Trying to set form control along the lines of
How to update field in table with datediff result
Why I’m getting Error in
Dep = Evt.Source.Model
?
Event = After update DEP
If I set Dep = Evt.Source difference in days is inserted in the control, but table does not update (of course I think).
 
Thanks in advance!

Option Explicit
Sub SetStay(Evt) ' source = DEP field
	Dim Grid As Object, Arr As Object, Dep As Object, Days As Object
	Dim dt_arr As New com.sun.star.util.Date
	Dim dt_dep As New com.sun.star.util.Date
	Dim d As Integer
	GlobalScope.BasicLibraries.LoadLibrary("MRILib")
	On Error GoTo Erro
	REM SET VARIABLES FOR THE CONTROLS:
	Dep = Evt.Source.Model
	Grid = Dep.Parent
	Arr = Grid.getByName("ARR")
	dt_arr = Arr.Date
	dt_dep = Dep.Date
	Days = Grid.getByName("DAYS")
	REM COMPUTE STAY DAYS
	d = DateDiff("d", CDateFromUnoDate(dt_arr), CDateFromUnoDate(dt_dep))
	Days.Value = d 
	Exit Sub
	Erro: MsgBox "ERRO " & Err & Chr(10) & "na linha " & Erl 
End Sub

Error_line_10

The standard approach is to add a line

mri Evt.Source

before the problematic line and examine that object.

:ok: but if I just print d
instead of trying to set control DAYS (as did when testing) no problem with
Source.Model
 
print_d

While you are alone observing a problematic situation, the possibilities of someone who wants to help are greatly limited.

Event to print = Mouse button released
 
And yes, you’re (of course) right: there is no .Model property in the problematic situation.

Can I upload the DB?
It is dummy, no real data.

What do the MRI “Services” and “Interfaces” tabs show?

This can speed up the process of finding the truth.

Porto.odb (13.2 KB)
The goal is after updating DEP (= depart date)
to set number of days.
Then user should be able to save the record.

I (and I’m afraid I’m not the only one) get the error described in this topic when opening your file.

Yes, I’ve seen this kind of problem…
As I was able to understand, one should never use “packed” LOs.
Always install it from TDF.
Thank you anyway :+1:

If you prepare an example with another built-in database (HSQLDB), then we can move on.

@sokol92
I was able to do it via Form (TableControl Parent) .Columns.DAYS
(not Control.Model)
updateInt(d)
But it can’t come to my mind why .Model Error
in Event = AfterUpdate
and not in Event = Mouse released (click on it)
:thinking:
Firebird 5.0.2
 
Anyway, thanks for your interest in helping!