Switching to design mode in form

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:30
Joined
Feb 28, 2001
Messages
30,557
I have a situation I can research for myself but if someone has run across this and already knows the answer, it would make my life easier. If not, I may just have discovered a "nasty" that eventually would have to be reported to Uncle Bill.

When developing a form that includes some auditing code, I am able to see that switching the form from Design View to Form View fires the Open event. Things I want to have happen in the event happen. In particular, some form context variables (in the form's general declaration area) are loaded based on a lookup table. This works OK.

Where I come to grief is when I try to switch back to Design View. The Unload event fires as though I'm going to close the form - but the context variables in the general declaration area have already been dereferenced. This happens before I have the chance to set the Cancel option of the Unload event entry. Therefore, my code makes the wrong choice. If I close the form using a more traditional method like a close button or the upper-right-corner X box, the context variables are still valid during the Unload event and the correct decisions are made. In fact, the context in that case appears to be valid trhough the Close event.

Has anyone else seen this behavior and do you know if anyone has reported this problem to Microsoft? I guess what I wanted to have happen would have been that the form's declarations stay valid until after the completion of the form's Close event. THEN switch to design view.

Does anyone see a problem with the idea that a form's declaration area variables shouldn't be destroyed until the Close event (rather than before the Unload event)?
 
Hmmmm. It's an interesting problem.

I believe I saw a post by Pat Hartman about something similar about a year ago. She wasn't asking but was advising that the OP close the form between changes to display mode, citing multiple nasties. I didn't pay a lot of attention at the time but I have found myself being more diligent since then about closing forms before/after working on the design.
 
I'm not able to replicate your result. In my test general declarations in the form were still available in the Close() event handler, including the values of textboxes bound to the recordsource of the form!!! This was unexpected. I'm using Access 2007. Maybe this is something that was changed for 2007, since I never remember form variables being available through the Close() event, though I would have expected them to stick around during Unload().
 
G’day Doc.

If I’m understanding the situation correctly you have code to cancel the Unload event.

It would seem to me that if that code did in fact work, it would cancel the Unload event and thereby prevent the switch to design view.

So I’m guessing that Microsoft has forced the condition which allows the switch to design view by overriding the Cancel.

Regards,
Chris.
 
I asked this on SuperUser.com:

Are you switching to design mode with the Access UI or in code?

If the latter, I question why there's ever a need in a production app to do so.

If the former, why do you need the variables to survive the switch?
 

Users who are viewing this thread

Back
Top Bottom