Table of contents

AllForms 对象 (访问)AllForms Object (Access)

office 365 dev account|上次更新日期: 2018/4/3
2 参与人员

AllForms集合包含一个AccessObject对象,用于每个CodeProject对象的当前项目中的窗体。The AllForms collection contains an AccessObject object for each form in the CurrentProject or CodeProject object.


当前项目CodeProject对象具有AllForms集合,该集合包含描述数据库中的所有窗体的实例的AccessObject对象。The CurrentProject and CodeProject object has an AllForms collection containing AccessObject objects that describe instances of all the forms in the database.例如,您可以枚举AllForms集合在 Visual Basic 来设置或返回该集合中的单个AccessObject对象的属性的值。For example, you can enumerate the AllForms collection in Visual Basic to set or return the values of properties of individual AccessObject objects in the collection.

您可以通过按名称,或在集合中的索引引用对象引用AllForms集合中的单个AccessObject对象引用。You can refer to an individual AccessObject object in the AllForms collection either by referring to the object by name, or by referring to its index within the collection.如果要引用AllForms集合中特定的对象,最好到窗体名称引用,因为窗体的集合索引可能会更改。If you want to refer to a specific object in the AllForms collection, it's better to refer to the form by name because a form's collection index may change.

AllForms集合进行索引从零开始的索引。The AllForms collection is indexed beginning with zero.如果要引用窗体的索引,第一种形式是 AllForms(0),第二种形式是 AllForms(1),依此类推。If you refer to a form by its index, the first form is AllForms(0), the second form is AllForms(1), and so on.

请注意 若要列出数据库中所有打开的窗体,请使用IsLoaded每个AccessObject对象AllForms集合中。Note To list all open forms in the database, use the IsLoaded property of each AccessObject object in the AllForms collection.然后可以使用每个AccessObject对象的Name属性返回窗体的名称。You can then use the Name property of each individual AccessObject object to return the name of a form.

您无法添加或删除AllForms集合中的一个AccessObject对象。You can't add or delete an AccessObject object from the AllForms collection.


下面的示例打印AllForms集合中每个打开的AccessObject对象的名称。The following example prints the name of each open AccessObject object in the AllForms collection.

Sub AllForms() 
    Dim obj As AccessObject, dbs As Object 
    Set dbs = Application.CurrentProject 
    ' Search for open AccessObject objects in AllForms collection. 
    For Each obj In dbs.AllForms 
        If obj.IsLoaded = True Then 
            ' Print name of obj. 
            Debug.Print obj.Name 
        End If 
    Next obj 
End Sub

下面的示例演示如何阻止用户窗体直接从导航窗格中打开特定窗体。The following example shows how to prevent a user form opening a particular form directly from the Navigation Pane.

示例提供的代码:Microsoft Access 2010 Programmer?s 参考Sample code provided by: TheMicrosoft Access 2010 Programmer's Reference

'Don't let this form be opened from the Navigator
If Not CurrentProject.AllForms(cFormUsage).IsLoaded Then
    MsgBox "This form cannot be opened from the Navigation Pane.", _
        vbInformation + vbOKOnly, "Invalid form usage"
    Cancel = True
    Exit Sub
End If



关于参与者About the Contributors

Wrox Press 秉承程序员到程序员的理念。Wrox 书籍由程序员为程序员编写,Wrox 品牌意味着对实际编程问题的权威解决方案。Wrox Press is driven by the Programmer to Programmer philosophy. Wrox books are written by programmers for programmers, and the Wrox brand means authoritative solutions to real-world programming problems.

另请参阅See also

其他资源Other resources

访问对象模型引用AllForms 对象成员Access Object Model ReferenceAllForms Object Members

© 2018 Microsoft