DoCmd.Close Method (Access)
The Close method carries out the Close action in Visual Basic.
Syntax
식 .Close(ObjectType, ObjectName, Save)
식 A variable that represents a DoCmd object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
---|---|---|---|
ObjectType |
선택 |
AcObjectType |
A AcObjectType constant that represents the type of object to close. |
ObjectName |
선택 |
Variant |
A string expression that's the valid name of an object of the type selected by the objecttype argument. |
Save |
선택 |
AcCloseSave |
A AcCloseSave constant tha specifies whether or not to save changes to the object. The default value is acSavePrompt. |
Remarks
You can use the Close method to close either a specified Microsoft Access window or the active window if none is specified.
If you leave the objecttype and objectname arguments blank (the default constant, acDefault, is assumed for objecttype), Microsoft Access closes the active window. If you specify the save argument and leave the objecttype and objectname arguments blank, you must include the objecttype and objectname arguments' commas.
참고
If a form has a control bound to a field that has its Required property set to 'Yes,' and the form is closed using the Close method without entering any data for that field, an error message is not displayed. Any changes made to the record will be aborted. When the form is closed using the user interface, Microsoft Access displays an alert.
To display an error message, use the RunCommand method to invoke the acCmdSaveRecord command before calling the Close method. This will cause a run-time error if one or more required fields are Null. This technique is illustrated in the following example.
Private Sub cmdCloseForm_Click()
On Error GoTo Err_cmdCloseForm_Click
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
Exit_cmdCloseForm_Click:
Exit Sub
Err_cmdCloseForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseForm_Click
End Sub
Example
The following example uses the Close method to close the form Order Review, saving any changes to the form without prompting:
DoCmd.Close acForm, "Order Review", acSaveYes