The Current Project Object

The CurrentProject object of the Application object returns a reference to the current project. The CurrentProject object has various properties, such as FullName and ProjectType, as shown here:

Debug.Print Application.CurrentProject.FullName Debug.Print Application.CurrentProject.ProjectType

These two lines of code will print the FullName and ProjectType properties of the current project to the Immediate Window. The CurrentProject object also has several collections, such as: AllForms, AllReports, AllMacros, and others. When you want to obtain a list of all forms in the project, regardless whether the form is open, you can use the AllForms collection. Here is an example.

Sub TestAllForms()

Dim objAccObj As AccessObject Dim objTest As Object

'set the object equal to the Current Project Set objTest = Application.CurrentProject

'loop through each form in the AllForms collection 'and print information about each Form to the 'Immediate Window.

For Each objAccObj In objTest.AllForms

Debug.Print objAccObj.Name Next objAccObj

End Sub

The preceding code declares a new instance of the CurrentProject object called objTest. Then, the name of each object that is a form in the AllForms collection of the objTest object is written to the Immediate Window.

0 0

Post a comment