I have a form frm_Test with record source tbl_Test. The table has a field named ID of type Long. The table has 5 records with values of ID = 1, 2, 3, 4, 5. The form has a text box bound to the field ID.
In the Form_Unload event, I have this code.
Private Sub Form_Unload(Cancel As Integer)
MsgBox "Unload ID = " & Me!ID
End Sub
I open the form and navigate to the record with ID = 3. Now I close the form and the MsgBox displays
Unload ID = 3
With other words, the values of the controls are properly set to the current record at the time of closing.
Now I use this form as the navigation target in a navigation control. This time, when I close the form, e.g. by navigating away, I get
Unload ID = 1
regardless of what the current record is at the time of closing.
This is a serious bug because it may break existing code, for example, if I want to cancel the closing of the form because some values in the current record are not valid.
Access version: 2016 MSO (16.0.10325.20082) 32-bit
Questions: Can you reproduce this behavior? Does it also occur on other versions of Access?
Workaround: I have to store the values that I want to use in the Unload event in module-wide variables in the Current and AfterUpdate events of the form.
You can download the zipped
TestUnload.accdb from OneDrive.
Matthias Kläy, Kläy Computing AG