Jan 13 2023 04:51 PM - edited Jan 13 2023 04:53 PM
I have a simple Main Form with one SubForm. On the Main Form I have a ListBox called "listItems" whose RowSource is set to a Query. If I issue a listItems.Requery, the Current event of the SubForm is triggered. Why is this happening? And is it possible to prevent the SubForm current event from triggering?
Jan 14 2023 04:13 AM
Jan 14 2023 05:44 AM
Jan 14 2023 06:05 AM
Jan 14 2023 06:15 PM - edited Jan 15 2023 07:02 AM
It's a little more trickier and complicated, because of the Subform requerying itself.
Does anyone know why this behavior happens like this? Same thing happens for combo boxes.
So what my Main Form and Sub Form do is, the Main Form has the Patient's information (Name, Address, etc...) and the Sub Form lists their Doctor's Appointments in a Datasheet by AppointmentDate. The List Box on the Main Form is supposed to list all the documents associated with this Patient's Appointment by using a Query as it's RecordSource the query has a WHERE condition that looks at the "ScheduleID" field of the SubForm (Current Record selected) to filter just those Documents for that "ScheduleID". That way, when the user clicks one of the rows of the Subform, which is an Appointment, I call the ".Requery" method of the ListBox so that it will run the query and show just those documents for that Appointment Date, and I also have code to change the label of the list box to say "Appointment Documents for: " & [AppointmentDate].
The bug-a-boo here is, when the SubForm requries itself when you call the ListBox.Requery event where the ListBox is located on the Main Form, the SubForm's current record is now in the 1st row, even though the user may have picked the 8th row. So all my logic in the Current() event, is not pointing to the row the user selected and because the current record of the SubForm is now in the 1st row, my listbox's Query which filters based on the current row (ScheduleID) of the SubForm, will display the wrong documents because it thinks the Current Record is the 1st row of the Subform. In actuality, what happens is, the Form_Current() event is put into an infinite loop because each time the Subform refreshes/requeries itself, it'll call the ListBox.Requery event thus causing the Subform to again refresh/requery itself and then again the SubForm's Form_Current() event will be triggered again.
The Form_Current() event can be triggered multiple times depending on how many SubForms I have on the Main Form. My particular SubForm, which lists the Appointments for the Patient chosen in a combo box in the Main Form's Header, it's Form_Current event is triggered 4 times when a user chooses a Patient from the combo box and the Main Form is refreshed/requeried to show the Patient's information (Name, address, etc...).
Again, why did they design it such that a SubForm will requery itself when a listbox or combo box is requeried on the Main Form???
Jan 15 2023 06:18 AM
Jan 15 2023 08:58 PM
Jan 17 2023 06:14 PM
Jan 28 2023 11:47 AM