Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2003
    Location
    Orlando Florida
    Posts
    20

    Cool Unanswered: Create a Report base on Listbox selection

    Hi All,

    I am trying to create a report based on the selection(s) from a listbox (on a form) using visual basic. I have searched the forum and tried some of the code available but: nothing is working so far. The code I was using does print the column names but no data on the report.

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim myList As Control
    Dim x As Integer, Strg As String
    Set myList = Forms!myForm!myList
    For x = 0 To myList.ListCount
    Strg = Strg & myList.ItemData(x) & vbCrLf
    Next x
    'Here, the DisplaytextBox control is located in the Detail section
    'and the controls 'CanGrow' property set to TRUE.
    Me.DisplayTextBox = Strg
    End Sub


    What am I doing wrong? Is there a better way to do this?

    Thanks for your help.

    B. Davis-

  2. #2
    Join Date
    Feb 2004
    Location
    Wales
    Posts
    343
    hi

    I have to produce a nuber of reports in using a combo as the "selector".
    However, I use the humble query, that way ill have less to do and besides I'm awful at sql and vb.

    But I use a query to populate the report simply by placing the Like[formname].[comboname] and have button set to open the report once the critera has been picked you could of course use the afterupdate to run a macro to open the report

    hope this little guide helps


    gareth

  3. #3
    Join Date
    Nov 2003
    Location
    Orlando Florida
    Posts
    20
    How are you running the query in the report? Are you using me.recordsource?

    B. Davis-

  4. #4
    Join Date
    Feb 2004
    Location
    Wales
    Posts
    343
    hi

    no im lazy - i set up a query and the using the wizard (see lazy) i set the report off that.

    hope its a quick fix

    gareth

  5. #5
    Join Date
    Feb 2004
    Location
    Dorset UK
    Posts
    147
    I know its not quite the stuff you are looking for but here is MS answer to every report in your database. (I have remove 2 of there lines of code ) I used this last week to populate a listbox, so I know every report in my database..

    You could use this to populate your listbox with every report ?


    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject


    For Each obj In dbs.AllReports

    Debug.Print obj.Name 'change this bit to additem to your listbox..

    Next obj

    I'm still trying to understand your initial problem.

    ~Ken

  6. #6
    Join Date
    Nov 2003
    Location
    Orlando Florida
    Posts
    20
    I have a form that has a listbox on it, in the listbox are the field names from a table. When the user selects the field name(s), I want to execute a report base on the field name(s) selected. This report will only pull back records base on the username. When the report is opened, it will contain only the fields selected (from the listbox) and the data for that field.

    Can this be done?

    Thank you for your time and consideration.


    B. Davis :-)

Posting Permissions

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