Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002

    Unanswered: Listbox Selections

    I have the following created:

    Form - frmCusts
    Query - qryCusts (created through the query window)

    On the form I have :
    Listbox - lstCust

    The query is a select query that returns sales transactions. I included a listbox that will allow me to filter the transactions based upon a customer number. I inserted a parameter in the criteria of the sales transaction to prompt for a customer number. This works fine. Now I am wanting to be able to select multiple customers. So I thought of putting the listbox on the form. However, I do not know how to get the data from my list box to the query parameter. I would appreciate any guidance.


  2. #2
    Join Date
    Feb 2002
    Try the following code:

    For intCurrentRow = 0 To Listbox.Listcount - 1
    If Listbox.Selected(intCurrentRow) Then
    strItems(intCurrentRow) = ListBox.Column(0, intCurrentRow)
    End If
    Next intCurrentRow

    Then you can use the strItems array to populate your parameters.

  3. #3
    Join Date
    May 2002

    ListBox -Revised

    I took a similar, but different path. I created a collection instead of an array (i suppose that an array is sort of a collection and vice-versa). I used the following code:

    Dim colCust As New Collection
    Dim varCust As Variant

    For Each varCust In lbCusts.ItemsSelected()
    colCust.Add lbCusts.Column(0, varCust)

    Now how do I go about getting the data in my collection (which are my customer numbers) to my parameter in my guery. Probably some what of a novice question, but I have not done this before.

    FYI, this quesry is a simple select query that I have created (not by code, mind you, but through the query window). The query is called qryCusts. I had at one time used a parameter criteria that prompts the user to type in a customer number and the query returns the data with the customer number the user types in. Now I need to filter on multiple customer numbers. With the list box, my users can select multiple customers and it populates the collection with the customer numbers. I just need to be shown how to use the collection as my parameter(s) in my query. Any help is appreciated.

  4. #4
    Join Date
    Jul 2002

    Re: ListBox -Revised

    I highly recommend the following book for any MS Access developer...especially if you are going to work with collections in MS Access. This book has helped me out in many situations in which I needed power programming help.

    WROX: Professional Access 2000 Programming
    ISBN: 1-861004-08-7
    Price: $50
    URL: Wrox's website
    Don't do today, what can be done tomorrow.

Posting Permissions

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