Data Management

How to populate an Access list control with report names

Use this simple VBA procedure to populate a list control with the names of all the reports in a Microsoft Access database.

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:

  1. Add a list or combo box to a form and name the control lstReports.
  2. Set the control's Row Source Type property to Value List.
  3. Click the Code button to launch the form's module.
  4. 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 lstReports.AddItem (ao.Name) Next End Sub Opening 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.

About Susan Harkins

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.

Editor's Picks

Free Newsletters, In your Inbox