Most VB collections have various methods or properties that will return information
regarding the collection of objects. The Forms Collection has only one property,
Count. This property gives the total number of forms currently loaded by the application.
To find the total number of forms in the project, just use code such as the following:
iFormCount = Forms.Count
To test the Forms.Count property in VB, use
a single form and place one command button on
the form. Open the code window for the command
button and type the code shown in Listing 4.14.
LISTING 4.14
PROGRAMMING WITH THE FORMS.COUNT PROPERTY
Sub Command1_Click()
Msgbox "The Forms Collection has "
& _
Forms.Count & _
" forms currently", _
vbInformation, "Forms Count"
End Sub
This code will show a message box with a string that contains the number of
forms in the collection. Remember that only loaded forms are in the collection.
Any form that has not been loaded or that has been unloaded will not be part of
the collection.
Using the forms collection topics
See Also