Microsoft Access 2010 tutorial:Docmd to close object


IX. DoCmd.Close

DoCmd.Cloe is a method used to close objects such as form, table, query, report, macro, module, etc. It has the following syntax:

DoCmd.Close (ObjectType, ObjectName, Save)

- ObjectType:  The type of object you intend to close.

- ObjectName: The name of an object that selected by ObjectType argument. It must be written between double quotes.

-Save: An constant that specifies to save changes the object or not. There are three types of Save argument:

       + acSaveNo: When you select this option, the saving changes to the object is not performed.

       + acSavePrompt: When you close the object, one message alerts to ask you to save or don't save the changing of the object. It is the default value of Save argument.

       + acSaveYes: The changing of the object is saved automatically without prompting.

The arguments of DoCmd.Close method can be blank. If you leave ObjecfType and ObjectName arguemnts blank,  Microsoft Access closes the active window. If you set Save argument and leave the ObjectType and ObjectName argument blank, the comma of ObjectType and ObjectName argument must be included.

For example, you intend to close the form BookSearch when you click Close button on this form. The prompting any changes to the form is performed when the form is closed. To solve the example, you need to apply the VBA code in CmdClose's click event procedure as the following:

Private Sub CmdClose_Click()
End Sub

Note: The name of Command Button is optional.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.