Referring to Open Objects
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
The Application object has properties that return collections of open Microsoft® Access objects. The Reports property returns a reference to the Reports collection that contains all currently open reports. The Forms property returns a reference to the Forms collection that contains all currently open forms. The DataAccessPages property returns a reference to the DataAccessPages collection that contains all currently open data access pages. You specify a member of a collection by using its name or its index value in the collection. You typically use the index value only when iterating through all the members of a collection because the index value of an item can change as items are added to or removed from the collection. For example, the following sample uses the form's name to reference the Open Customers form:
Dim rstCustomers As ADODB.Recordset
Set rstCustomers = Forms("Customers").Recordset
The next example closes and saves all open data access pages by looping through the DataAccessPages collection:
For intPageCount = DataAccessPages.Count - 1 To 0 Step -1
DoCmd.Close acDataAccessPage, _
DataAccessPages(intPageCount).Name, acSaveYes
Next intPageCount
The Forms, Reports, and DataAccessPages collections contain only open objects. To determine if an object is open, you can use the IsLoaded property of an item in the AllForms, AllReports, or AllDataAccessPages collections, or you can use the SysCmd method with the acSysCmdGetObjectState constant. You can also use the CurrentView property to determine if a form is open in Design, Form, or Datasheet view or if a data access page is open in Design or Page view. The following procedure uses the SysCmd method and the CurrentView property to determine if a form is open in Form or Datasheet view:
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
Const OBJ_STATE_CLOSED = 0
Const DESIGN_VIEW = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> OBJ_STATE_CLOSED Then
If Forms(strFormName).CurrentView <> DESIGN_VIEW Then
IsLoaded = True
End If
End If
End Function
See Also
Working with Reports, Forms, and Data Access Pages | The Data Behind Forms and Reports | Working with Controls on Forms and Reports | Working with Data Access Pages