Unloading a form

S

SMERTZ

I am trying to unload a form, or close it on the click of a button to return
to the main switchboard form. So in the click event of the cmd button at the
end of the code I have placed the line
frmCustomer.unload

Access VBA does not seem to recognize this. So what would be the proper
syntax to unload a form? Or better yet all forms except the main
switchboard form?


Thanks.
 
A

Albert D.Kallal

frmCustomer.unload

You should try compiling your code before you run it...the above likely did
not compile let alone run. So, it is a good idea to compile code before you
try and run it.

Anyway, the correct syntax to close a form in ms-access is:

docmd.Close

better yet, is:

docmd.Close acForm, "your form name goes here"

And, even better is;

docmd.Close acForm, me.name

Note that you can use the first example, docmd.Close, however, if you have
some code, or a form focus changes, then in fact the code will close the
form that has the focus (99% of the time, that will be the form that you are
closing, but some caution is needed).

If for some strange reason, you are using multiple instances of a form, and
did NOT open the form via docmd.OpenForm (this is a the correct syntax to
open a form by the way), then the forms() collection will NOT have that
instance of the form in the collection.

If this is a instance of the form, then simply set that var to nothing, and
the form will close as the object goes out of scope....
 
Top