none
Bug in Form Unload Event when the form is used in a Navigation Control RRS feed

  • Question

  • 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

    Saturday, August 18, 2018 11:21 AM

All replies

  • 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

    Hi Matthias,

    Is Me the expected form? Did you check Me.Name?

    Still using A2003 with no experience with navigation controls, I use quite a lot of generalized subforms. To see whether I am referring to the right subform, I use suborm.Name quite a lot in the debug phase.

    Imb.

    The forum misspelled my name a little bit …

    Hi Matthias,

    Is Me the expected form? Did you check Me.Name?

    Still using A2003 with no experience with navigation controls, I use quite a lot of generalized subforms. To see whether I am referring to the right subform, I use suborm.Name quite a lot in the debug phase.

    Imb.


    • Edited by Imb-hb Saturday, August 18, 2018 2:15 PM
    Saturday, August 18, 2018 2:11 PM
  • The Me keyword always references the Class in which the code is written. So when the code is behind the form frm_Test in its Unload event, then Me always references frm_Test. No need to check the name.

    Matthias Kläy, Kläy Computing AG

    Saturday, August 18, 2018 6:41 PM