Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2012
    Posts
    68

    Unanswered: Populate a list box with reports

    I've read a bunch of threads on here as to how to populate, but just cant get it .

    I found this code:
    Code:
    Dim Ctr As Container
    Dim Db As Database
    Dim Doc As Document
    Dim StrName As String
    Dim StrReportList As String
    
    Set Db = CurrentDb()
    Set Ctr = Db.Containers("Reports")
    
    Ctr.Documents.Refresh
    
    For Each Doc In Ctr.Documents
    StrName = Doc.Name
    StrReportList = StrReportList & StrName & ";"
    Next Doc
    
    Me.LstReports.RowSourceType = "value list"
    Me.LstReports.RowSource = StrReportList
    But have no idea where to place it. I placed it in the code but received an error on the second to the last line.


    I just want to populate a listbox with the reports in the DB.

  2. #2
    Join Date
    Jan 2012
    Posts
    97
    Hope this helps,

    Dave.

    _____________

    Access 2000 User

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Use this code in the module of the form where the listbox (named: List_Reports in this example) is located:
    Code:
    Private Sub Form_Open(Cancel As Integer)
    
        Me.List_Reports.RowSourceType = "Value List"
        Me.List_Reports.RowSource = ListAllReports
        
    End Sub
    
    Private Function ListAllReports() As String
    
        Const c_ListSeparator As String = ";"
    
        Dim AccObj As AccessObject
        
        For Each AccObj In Application.CurrentProject.AllReports
            If Len(ListAllReports) > 0 Then ListAllReports = ListAllReports & c_ListSeparator
            ListAllReports = ListAllReports & AccObj.Name
        Next AccObj
    
    End Function
    If the list separator is not the semicolon (;) is your locale, change the definition of the constant c_ListSeparator accordingly.
    Have a nice day!

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Perhaps a little simpler, with the Row Source Type set to Table/Query just put this in the Row Source Property of the Listbox:
    Code:
    SELECT MSysObjects.Name FROM MsysObjects WHERE (Left$([Name],1)<>"~") And (MSysObjects.Type)=-32764 ORDER BY MSysObjects.Name;
    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Mar 2012
    Posts
    68
    Thanks all for your solutions. I used Linq's method as it was the easiest.

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad we could help!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Mar 2012
    Posts
    68
    I should have asked this all as one question, but i'm trying to teach myself. The next step is to be able to print a selected report from the listbox.

  8. #8
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Exactly how do you want to do this?

    • Do you want to click on the Report in the Listbox and have it Print immediately?
    • Do you want to click on the Report in the Listbox and view it in Preview Mode, then Print it?
    • Do you want to click on the Report in the Listbox and have a Command Button to Print it?

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •