Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Unanswered: clearing and repopulating contents of a listbox

    I have a listbox holding the names of all our users.
    Beneath I have 2 checkboxes ('Male' and 'Female')
    When I select 'Male' I want the contents of my listbox cleared and repopulated with only the male users.
    Same story when selecting Female.
    When both chekboxes are selected all the users should be shown.


    What's the easiest way to get this done?

  2. #2
    Join Date
    May 2002
    Location
    Atlanta, GA
    Posts
    117
    Hey artemide,

    I use a method in vb. Lets say your list box name is mylist. I would do something like the following.

    Private Sub popList()
    Dim mySQL as String
    If Me.malecheck = True Then
    mySQL = "SELECT field FROM table WHERE(gender = 'Male')"
    ElseIf
    Me.femalecheck = True Then
    mySQL = "SELECT field FROM table WHERE(gender = 'Female')"
    End If
    Me.mylist.RowSource = mySQL
    End Sub

    Then for your checkboxes you can use On Click events:

    Private Sub malecheck_OnClick()
    If Me.malecheck = True Then
    Call popList
    End If
    End Sub

    And then do the same for the female check.

    Of course this is just an example, but its the best way to change the row source for list box.

    Later, Kal

  3. #3
    Join Date
    Jan 2003
    Posts
    46
    Artemide,

    I think you may be better served by replacing the checkboxes with an option group control with 3 options (Male, Female, Both). Less ambiguity for users.

    Each option can return a different value (1, 2, 3). Then use the option group's click event to change the listbox's rowsource.

    Select Case strSQL
    Case 1: strSQL = "Your SQL string":
    Case 2: strSQL = "Your SQL string"::
    Case 3: strSQL = "Your SQL string"::
    End Select

    Me.YourListBoxName.rowsource = strSQL

    'check to see if you need to requery the listbox. If so:
    Me.YourListBoxName.requery

    Cheers,
    Zambezibill

Posting Permissions

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