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?

Microsoft 365 and Office | Access | Development
Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. DBG 11,531 Reputation points Volunteer Moderator
    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 3,381 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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.