[AccessD] Closing a form from a module procedure

Stuart McLachlan stuart at lexacorp.com.pg
Fri Dec 17 19:53:45 CST 2004


On 17 Dec 2004 at 20:37, Barbara Ryan wrote:


> Simply put, in an Access 97 application I have Form1 and Module1.  A
> pushbutton on Form1 executes a procedure in Module1 which closes Form1
> (DoCmd.Close acForm, "Form1", acSaveNo) and then deletes Form1
> (DoCmd.DeleteObject acForm, "Form1").  However, the Close command does not
> appear to be working --- I receive an error on the DeleteObject command,
> saying that Form1 is still open.  Yet when I run the following IsLoaded
> function after the Close command, it returns false (i.e., Form1 is NOT
> open).

Trying to explain it simply without getting into details about stacks, 
pointers, calls etc:

While running the module procedure, a pointer will still be open saying 
where to return execution to once the procedure is over. SInce that pointer 
is to a a procedure in the form, the system cannot "completely close" the 
form at that stage.  It can remove the name from the Forms collection, but 
it can't clean up and get all traces of the form out of memory until the 
pointer has been used and removed.

Even though the actual delete command is not in the form's module, what you 
are doing is effectively the same as trying to delete the form from code 
within the form.




-- 
Stuart





More information about the AccessD mailing list