Got it. I would recommend using Gallery1 with those names rather than a ListBox. This will allow you to reference each entry with:
Last(FirstN(pupils,#)).Name
Gallery1 will not fit inside the Form, so this solution would work independent of one. So rather than using SubmitForm, you could setup a Timer control that Patches for the number of items selected the Gallery1. This method will need to manually reference each argument in the Form, but it will Patch automatically. See @hpkeong's post for more information.
checkicon.OnSelect:
UpdateContext({savenames: true, iter: 0})Timer1.Text: iter
Timer1.AutoPause: false
Timer1.AutoStart: savenames
Timer1.Repeat: savenames
Timer1.Start: savenames
Timer1.OnTimerEnd:
If(savenames,
If(iter<CountRows(Gallery1.AllItems),
UpdateContext({iter: iter+1});
Patch(goinghome,Defaults(goinghome),
{Date: TextInput1.Text,
Time: TextInput2.Text,
Pupil: Last(First(pupils,iter)).Name
}
),
UpdateContext({savenames: false});
NewForm(Form1)
)
)
This formula will Patch until the iteration number, iter, is equal to the number of items selected in your Gallery of names. It will count up one each time. At its conclusion, it will stop the timer and clear the form.