Can I reference form data during the Unload event

Morten Lamoey 6 Reputation points
2021-09-15T19:34:38.8+00:00

I have a form where I need to do some processing during the Unload event. In the Unload event, I then reference form data successfully 99.99% of the time, but every so often, I get an error indicating that the form may already be closed.

However, I have an error report that fires due to the above-mentioned error, where I list all the open forms, and the form where I'm running the unload event is still listed as open.

Are there any reason I should not reference a form during its Unload event?

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
825 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. DBG 2,301 Reputation points
    2021-09-16T13:47:05.527+00:00

    Just FYI, earlier discussion on this topic is available at AWF.

    https://www.access-programmers.co.uk/forums/threads/form-closes-before-unload-event.319483/


  2. Ken Sheridan 2,666 Reputation points
    2021-09-17T12:00:14.457+00:00

    If you assign the data in the form's controls to a globally exposed array in the form's Current event procedure, and in its AfterUpdate event procedure you'll then be able to read data from the array even if the form has closed.

    What would you want to do if the form is at an empty new record? If you don't want to assign Nulls to the array, you'd need to make the assignment in the Current event procedure conditional on the NewRecord property being False.