다음을 통해 공유


AllForms Collection

The AllForms collection contains an AccessObject object for each form in the CurrentProject or CodeProject object.

Remarks

The CurrentProject and CodeProject object has an AllForms collection containing AccessObject objects that describe instances of all the forms in the database. 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.

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. 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.

The AllForms collection is indexed beginning with zero. If you refer to a form by its index, the first form is AllForms(0), the second form is AllForms(1), and so on.

참고

To list all open forms in the database, use the IsLoaded property of each AccessObject object in the AllForms collection. You can then use the Name property of each individual AccessObject object to return the name of a form.

You can't add or delete an AccessObject object from the AllForms collection.

Example

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.

Sample code provided by:Access 2010 프로그래머 참조 책 표지 The Microsoft Access 2010 Programmer’s Reference | About the Contributors

'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(영문일 수 있음)는 프로그래머가 프로그래머를 위해 집필한 서적을 전문으로 출판하는 업체로, 이러한 서적에서는 실제 프로그래밍 관련 문제에 대한 신뢰할 수 있는 해결 방법을 제공합니다.

참고 항목

개념

Access Object Model Reference

AllForms Object Members