Close Method (Microsoft Access)

Close Method

See Also         Example         Applies To

The Close method carries out the Close action in Visual Basic. For more information on how the action and its arguments work, see the action topic.

Syntax

DoCmd.Close [objecttype, objectname], [save]

The Close method has the following arguments.

Argument Description
               
objecttype One of the following intrinsic constants:
  acDataAccessPage
acDefault
(default)
acDiagram
acForm
acMacro
acModule
acQuery
acReport
acServerView
acStoredProcedure
acTable
  Note   If closing a module in the Visual Basic Editor (VBE), you must use acModule in the objecttype argument.
objectname A string expression that's the valid name of an object of the type selected by the objecttype argument.
save One of the following intrinsic constants:
  acSaveNo
acSavePrompt (default)
acSaveYes
  If you leave this argument blank, the default constant (acSavePrompt) is assumed.

Remarks

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.

Note   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 Windows Close button, the Close action in a macro, or selecting Close from the File menu, Microsoft Access displays an alert. The following code will display an error message when attempting to close a form with a Null field, using the Close method.

If IsNull(Me![Field1]) Then
    If MsgBox("'Field1' must contain a value." _
        & Chr(13) & Chr(10) _
    & "Press 'OK' to return and enter a value." _
    & Chr(13) & Chr(10) _
    & "Press 'Cancel' to abort the record.", _
        vbOKCancel, "A Required field is Null") = _
        vbCancel Then
        DoCmd.Close
    End If
End If