Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List box summary

Status
Not open for further replies.

lilal111

Technical User
Sep 16, 2008
18
CA
I have an application that has two list boxes, lstbox1 and lstbox2. lstbox1 allows the user to select items from lstbox1 and place them into lstbox2 .I would like to know if its possible to summarize the specific amounts of items individually from lstbox2?

For Example:

lstbox1 lstbox2
widget 1 widget 1
widget 2 widget 1
widget 3 widget 2
widget 4 widget 3

You have purchased following

2 widget 1
1 widget 2
1 widget 3

Any help would be appreciated.
 


hi,

What have you tried?

Arrays?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
This returns a summary collection for any single column listbox. Then you can do what you want to with the collection. Load another listbox, print a concatenated string.
Code:
Public Function getListSummaryCol(lst As Access.ListBox) As Collection
  On Error GoTo errlbl
  Dim I As Integer
  Dim j As Integer
  Dim itm As String
  Dim itmCount As Integer
  Dim col As New Collection
  Dim colSummary As New Collection

  For I = 0 To lst.ListCount - 1
    itm = lst.ItemData(I)
    col.Add itm, itm
  Next I
  
  For I = 1 To col.Count
    itmCount = 0
     For j = 0 To lst.ListCount - 1
     If col(I) = lst.ItemData(j) Then itmCount = itmCount + 1
    Next j
    colSummary.Add itmCount & " " & col.Item(I)
 Next I
 Set getListSummaryCol = colSummary
 Exit Function
errlbl:
  If Err.Number = 457 Then
     Resume Next
  Else
    MsgBox Err.Number & " " & Err.Description
  End If
End Function

Code:
'test
Private Sub Command2_Click()
  Dim col As Collection
  Dim I As Integer
  Set col = getListSummaryCol(Me.List0)
  For I = 1 To col.Count
    MsgBox col(I)
  Next I
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top