Hi @TYNAI,
I've made a test of this that updates the amount of available leave hours of staff instantly. How I have done this.
Created two tables: Staff and StaffLeave


This is the small test I have made.

--------------------------------------------------------------------------
The code:
For the buttons OnSelect property, I have:
Set(varLeaveType, "Annual"); // Change the leave tpye for each button
For the Text Input (Hours Off) in the Default property:
DateDiff(DatePicker1.SelectedDate, DatePicker2.SelectedDate) * 8
\\ I am assuming 8 hours is the standand amount of hours in a working day
The Visible property is still the same
For the Submit button, the OnSelect property:
Patch(StaffLeaves,
Defaults(StaffLeaves),
{
StaffName: LookUp(Staff, Name = User().FullName),
LeaveType: varLeaveType,
DateFrom: DatePicker1.SelectedDate,
DateTo: DatePicker2.SelectedDate,
LeaveTakenHours: Value(TextInput1.Text)
}
);
With(
{
staffDetails:
{
staffName: LookUp(Staff, Name = User().FullName),
staffAL: LookUp(Staff, Name = User().FullName).AnnualLeave,
staffSL: LookUp(Staff, Name = User().FullName).SickLeave,
staffML: LookUp(Staff, Name = User().FullName).MaternityLeave
}
},
Switch(varLeaveType,
"Annual",
Patch(Staff,
staffDetails.staffName,
{
AnnualLeave: staffDetails.staffAL - Value(TextInput1.Text)
}
),
"Sick",
Patch(Staff,
staffDetails.staffName,
{
SickLeave: staffDetails.staffSL - Value(TextInput1.Text)
}
),
"Maternity",
Patch(Staff,
staffDetails.staffName,
{
MaternityLeave: staffDetails.staffML - Value(TextInput1.Text)
}
)
)
)
Let me know if you need any more help with this.
Please tick Accept as solution if the answer is useful.
Thanks,
@AARON_C