Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Posts
    18

    Unanswered: How do you reference on a report the listbox contents on a form?

    Here's the question. On a form I have a listbox whose contents are determined by a SQL statement within an If...Then structure.

    I need the form's list box contents to appear on a report. Do I use a list box to display or some other control, a text box maybe? Or, if I use a list box, how do I code the reference to the form list box contents?

    Thanks in advance for any suggestions.

    Amadea

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Well.... just off the top of my head real quick, try this. Place the following code into the 'Format' event of the report section (ie: Report Header, or Page Header, or Detail, etc.) where you what the list box contents to be displayed:

    Code:
    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
    There are a lot of different possibilities to play with. Put the retreived data into whatever you want.

    FF

  3. #3
    Join Date
    Dec 2003
    Posts
    18
    Wow. That works great! You're wonderful. What if the list box includes two columns? Can I reference the data by adding (0) and (1) somewhere? or .Column(0) and .Column(1) as you would in other instances? You see what I mean. My list box has two columns of info.

    In the x = 0 , is the 0 the first list item or the first column in the list. mmm, I'll bet it's first list item, doesn't seem like a logical guess.

    Sorry to be so dense. I'm reaching a little beyond my scope, but that's how I learn.

    Thanks greatly for your input. I really do appreciate your response.

    Amadea

    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

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Code:
    Strg = Strg & myList.Column(n).ItemData(x) & vbCrLf

  5. #5
    Join Date
    Dec 2003
    Posts
    18
    Strg = Strg & myList.Column(n).ItemData(x) & vbCrLf

    Aaaaa....see, I was checking my reference materials and thought that using Column(x, y) and ColumnCount() would have to be incorporated. Didn't think about Column() *before* ItemData().

    Thank you for your help.

    Amadea

Posting Permissions

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