How to close (unload) a form

2019-06-24 09:12发布

问题:

I have a form that has some buttons, and when user click on a button, the form should be closed (unloaded). I used the following methods, but all generate error:

docmd.close me

unload me

What is the best way to close or unload a form in VBA (from code inside the form)

回答1:

DoCmd.Close expects ObjectType as its first argument, followed by ObjectName which is a variant string as the object name.

So in the click event of a command button which is intended to close the current form, I use this ...

DoCmd.Close acForm, Me.Name