Close


Closes the window of an Access object.

Syntax

DoCmd.Close([ObjectType][, ObjectName][, Save])

with the following parameters:

ObjectType

An AcObjectType constant indicating the type of object to close. Possible values are acDataAccessPage, acDefault (the active window), acDiagram, acForm, acFunction, acMacro, acModule (a VBA module), acQuery, acReport, acServerView, acStoredProcedure, and acTable.

ObjectName

A String indicating the name of an object of type ObjectType.

Save

An AcCloseSave constant indicating whether changes should be saved. Possible values are acSaveNo, acSavePrompt (the default value), and acSaveYes.

Example

The example iterates the AllTables collection to determine if a table is open. If it is, it prompts the user to close it.

Public Sub CloseTables() Dim tbls As AllTables Dim tbl As Variant Set tbls = Access.Application.CurrentData.AllTables For Each tbl In tbls   If tbl.IsLoaded Then   If vbYes = MsgBox("Close " & tbl.Name & "?") Then   DoCmd.Close acTable, tbl.Name, acSavePrompt   End If   End If Next End Sub 

Comments

  • If the object to be closed is a form with a required field that is blank, no error or warning will be displayed, and any changes will be aborted. This contrasts with forms closed by the Close button, the Close macro action, or the File | Close menu item, all of which display a message box in this case.

  • Close is typically used with all of its optional arguments omitted to close the object from which the code is running. The optional arguments are typically supplied when the Close method is used to close some other object.

  • No error is generated if ObjectName is not open or does not exist. Instead, the method call is simply ignored.




Access VBA Programming
Microsoft Access VBA Programming for the Absolute Beginner
ISBN: 1598633937
EAN: 2147483647
Year: 2006
Pages: 214
Authors: Michael Vine

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net