I didn't quite test your implementation on my database, twgonder
But I did some testing with the idea of removing the test variable and using the .Tag property of the form. Basically, assign something to the .Tag in the same code you instance it, then you can reference it within events. I could not make it work with the Load or the Open events, but I was able to make it work with the Close event. Take a look at the database attached.
Database4-2.accdb
It obviously depends on what you want to do with this variable, but you can place data there and the Close event will pick it up. You can get creative with that, for instance, if you want to store a name, a number and a date, you could store in the Tag something like "Tomas,123,#1/1/2022#" and later retrieve it with Split.
I know it's not great, but hey, it's an idea.