I've got a form (frmNewHours) with some controls on it which I use to alter the subform (tblHoursSubform), which is a datasheet view subform containing 2 visible columns for the user (Project and MTDHours). I want the subtotal of the MTDHours column displayed in an unbound field on my main form.
What I tried first:
- I put an unbound control (Subtotal) in the main form
- In the Form Footer of the subform I put an unbound control (HoursSubtotal) with a control source =Sum([MTDHours])
- In the Subtotal control on the main form, I set it's control source to =[tblHoursSubform]![HoursSubtotal]
This worked perfectly at first, but as I continued to develop the form (maybe irrelevant details, but I use a couple controls on the main form to change the recordsource for the subform and the recordsource of the Project combobox control in the subform) the subtotal display stopped working. I deleted the subtotal controls and recreated them the exact same way and it worked again, which didn't really make sense to me but I continued on.
I finished developing the form and tested it on another computer, and the subtotal field stopped working again (the subform's control is erroring for some reason)
What I tried next:
- I wrote a function that queries and returns the subtotal, and changed the control source to =GetHoursSubtotal(GetUserID(),[SelectedSession])
This works when the form is loaded, but as data in the subform changes the subtotal does not update, so I added the following code to the subform:
Private Sub Form_Current()
Me.Parent.Controls("Subtotal").Requery
End Sub
While this works, it takes about a full second to refresh the subtotal control, during which the control is empty. So while it's functional, it's definitely not working as intended.
So now I'm at a loss for what to try next. Has anyone else experienced this and found a solution?
EDIT: Got it working. I went back to the original solution somewhat, but I changed the subtotal's control source to =Nz(Sum([MTDHours]),0) and now no more problems.