Closing one instance of a form

DataMinerHome

Registered User.
Local time
Yesterday, 21:29
Joined
Jan 4, 2010
Messages
57
I am using Allen Browne's code http://allenbrowne.com/ser-35.html to open multiple instances of a form.

I have a button on the form which does:
DoCmd.Close acForm, Me.Name
And in the on-close event I have:
RemoveInstance Me
(see the link to see what RemoveInstance does)

However, when I use the button to close a form instance, the wrong instance closes. It seems the instances always close in the order that they were opened, regardless of which instance I am actually trying to close. The hwnd for me.name always seems to be the "oldest" in the collection of open instances.

When I use the standard "X" in the upper right corner of the form to close the instance, the correct instance closes.

So, what code do I need to put behind my button to get the correct instance to close?


OKay, never mind, I found another thread in this forum that just says to use Form_Close. That seems to work. But here's another question: When you use the Access wizard to create a close button on a form, it (in past versions of access) directed you to docmd.close, and now in access 2007 it creates an imbedded macro. So, do the folks at microsoft know something I don't know? Why in the world wouldn't you always just use Form_Close????
 
Last edited:
I could not see a RemoveInstance in the link provided.

Form_Close is not a statement to close the Form, it's a call to the Form_Close event.
 
Sorry, my mistake. RemoveInstance is basically the code shown in the form close event.

Yes, I realized that about Form_Close about 5 minutes after I posted... duh!

Anyway, just having my button call the Form_Close event seems to work fine.
 

Users who are viewing this thread

Back
Top Bottom