Show list box selections in text box on report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BarbQb
    New Member
    • Oct 2010
    • 31

    Show list box selections in text box on report

    Hi All.

    I have a form where I can select multiple CustomerID's for my report. At the top of the report I have a text box that I would like to disply the Customer ID's that the user selected

    This is what I have for the text box

    ="Customer ID: " & Forms.frm_AllCu st.Customer

    This code doesn't return anything on the report, just shows "Customer ID: " (shown without the "")


    Any help would be great
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Are the Multiple CustomerIDs on frm_AllCust displayed in a List Box named Customer? If so, what is the RowSource for the List Box? You must be more specific as to where and how these IDs are displayed on the Form.

    Comment

    • BarbQb
      New Member
      • Oct 2010
      • 31

      #3
      Sorry about that.

      List box and the rowsource:

      frm_AllCust.Cus tomer

      Code:
      SELECT qryCustomer.Customer_ID 
      FROM qryCustomer 
      ORDER BY [Customer_ID];
      Last edited by NeoPa; Oct 11 '10, 10:49 PM. Reason: Please use the [code] tags provided.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        From the Report's Activate() Event, you can actually build a String (Comma Delimited in this case) of CustomerIDs Selected on frm_AllCust, then display it in a Text Box (txtIDs) in the Report's Header Section, as in:
        Code:
        Private Sub Report_Activate()
        Dim lst As Access.ListBox
        Dim varItem As Variant
        Dim strBuild As String
        
        Set lst = Forms![frm_AllCust]![Customer]
        
        If lst.ItemsSelected.Count > 0 Then
          For Each varItem In lst.ItemsSelected
            strBuild = strBuild & lst.ItemData(varItem) & ","
          Next varItem
            Me![txtIDs] = Left$(strBuild, Len(strBuild) - 1)
        End If
        End Sub

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32662

          #5
          ADezii, you've changed your avatar again!! I'm struggling to keep up :-D

          As for the problem, there is another way to approach this if you assume that the report has already been called with the WhereCondition parameter set to list the relevant [Customer ID]s. The Filter property of the report will contain something like :
          Code:
          [Customer ID] In(X, Y, Z, ...)
          Simply strip the "[Customer ID] In(" and the ")" from the string and add it into the TextBox control displaying the title.

          Comment

          Working...