Microsoft Access Office VB VBA Help and Examples
           
             

Fill a Combo Box with a List of Reports

This piece of code shows you how to fill a combo box with a list of reports within the current database.

Create a form and put an unbound combobox on the from and call it ReportList. Then put the following code in the form open event.

Private Sub Form_Open(Cancel As Integer)
    Dim Dbs As Database
    Dim Rpc As Container
    Dim Rpt As Document
    Set Dbs = CurrentDb
    Set Rpc = Dbs.Containers!Reports
    For Each Rpt In Rpc.Documents
        ReportList.RowSource = ReportList.RowSource & Rpt.Name & ";"
    Next
    ReportList.Requery
    Set Dbs = Nothing
    Set Rpc = Nothing
    Set Rpt = Nothing
End Sub

After the form loads you'll have a combobox with a list of the reports available. Once a user has selected a report you could have a button which opens the report or prints it maybe. To find out the report name just use Me.[ReportList].Value

Alternatively if you want to be a little smarter. Just put a listbox on a form and set it's rowsource to :-

SELECT Name FROM msysobjects WHERE (((msysobjects.Type)=-32764));
 
HOME   SEARCH SITE   PRIVACY POLICY   CONTACT
The code and application content of this site is copyright of Smiley I.T. and as such reproduction in any form which is for commercial use requires the permission of the Webmaster. Any use of this code for non-commercial use only requires a link or comment back to the original page you took the code from.