Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    327
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding Values to a listbox (Access 2000)

    I am trying to add a value selected from a combo box (the whole row actaully) to a listbox, but I am unsure of how to add a value to a listbox. Any examples of how to add values to a listbox would be great.

    Thanks

  2. #2
    Star Lounger
    Join Date
    Jan 2003
    Location
    Grass Valley, California, USA
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Values to a listbox (Access 2000)

    (Edited by HansV - replaced leading spaces by <!t>[tab]<!/t> tags to preserve indentation)

    I'm trying to imagine a situation where a combo box selection would/could alter the content of a listbox. The only situation where I've altered a listbox content based upon other control field input was a case where I had a "Name" field on the form, as well as the listbox. I allowed the user to start keying in a name, and on each keystroke rebuilt a query to display a list of names that satisfied the character string entered so far. When the displayed list was short enough to observe the desired name, the user could then click on the actual name in the list box, resulting in that person's full name and other data to be obtained and displayed on the form.

    The monitoring of the keyed input, and the creation of the query uses the following code:

    Private Sub txtLastName_KeyPress(KeyAscii As Integer)
    If KeyAscii = 9 Then Exit Sub ' Check for Tab
    If KeyAscii = 13 Then Exit Sub ' Check for CR
    If KeyAscii = 8 Then ' Check for BS
    If Len(strLName) > 0 Then
    strLName = Left(strLName, Len(strLName) - 1)
    End If
    GoTo bldQryLName
    End If
    strLName = strLName & Chr(KeyAscii)
    bldQryLName:
    Me.txtLastName.Value = strLName
    txtLastName.SetFocus
    bldListQry
    End Sub

    Private Sub bldListQry()
    Dim strWhere As String
    Dim ii As Integer
    strWhere = ""
    strSql = "SELECT * FROM qryClientList"
    If Len(strLName) > 0 Then
    If Len(strWhere) = 0 Then
    strWhere = " WHERE LastName LIKE '" & strLName & "*'"
    Else
    strWhere = strWhere & " AND LastName LIKE '" & strLName & "*'"
    End If
    End If
    ' See if any WHERE clause generated
    If Len(strWhere) > 0 Then
    strSql = strSql & strWhere
    End If
    ' Set new lstClients query
    Me.lstLookup.RowSource = strSql
    Me.lstLookup.Requery
    End Sub

    Perhaps you can adopt the above to your combo box input...

    -- Jim

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Adding Values to a listbox (Access 2000)

    How you do it depends on the rowsource for both the combobox and the listbox. Are they populated with value lists, field lists, table, queries, or what?
    Charlotte

Posting Permissions

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