Populating a list or combo box with all the reports in a database is an easy way to present all the reports. By choosing a report from the control, users can quickly view or print a report without knowing how to do so from the Database window. Fortunately, the task requires just a bit of code behind the form. To populate a list control in this way, do the following:
- Add a list or combo box to a form and name the control lstReports.
- Set the control's Row Source Type property to Value List.
- Click the Code button to launch the form's module.
- Enter the following code:
Private Sub Form_Load()
'Populate lstReports with the name
'of all the reports in the database.
Dim ao As AccessObject
For Each ao In CurrentProject.AllReports
End SubOpening the form in Form view executes the form's Load event. The For loop cycles through the reports in the AllReports collection, which contains objects that describe instances of all the reports in the database.
Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.