Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006

    Unanswered: Reset listboxes to no selections

    I am reading in my Access book as I post this but wanted to go ahead and throw it out there in case I didn't find an answer.

    I have a form with a couple of multi-select listboxes that are used to drive a query.

    I would like to add a button to this form that will allow me to set the listboxes to where no items have been selected. In essence resetting the form without having to close it.

    Can anyone out there supply the code (I am sure it is something simple like mylstbox.Value = Null) to do that?


  2. #2
    Join Date
    Nov 2004
    I don't quite remember, but I think for single select listboxes, you could do just

    me!lstMyList = Null

    as you suggested, but for multiselect, I think perhaps loop the selected items and set selected to false, but also resetting the rowsource should work

    me!lstMyList.rowsource = me!lstMyList.rowsource

  3. #3
    Join Date
    Feb 2006

    Thanks for the reply. I am playing around with the ideads you gave but am getting some errors right now. I will continue to work on this but any other ideas are appreciated (or the code to make this work ).

  4. #4
    Join Date
    Feb 2006

    Thanks for your suggestions. I was able to get it to work using code like that shown below. I would still think there is an easier way to do it but this certainly works.

    Private Sub btnClear_Click()
    On Error GoTo Err_BuildQry
    ' Section 1 - This section handles the variable declarations
    Dim strSQL As String
    Dim qdf As QueryDef
    Dim qryName As String
    Dim db As Database
    ' End Section 1
    ' Section 2 - This is the section that resets lstMfgLoc
    strSQL = "SELECT tblItems.MfgLoc" & Chr(10) & "FROM tblItems" & Chr(10) & "GROUP BY tblItems.MfgLoc;"
    Forms!frmDataSelector2!lstMfgLoc.RowSource = strSQL
    ' End Section 2
    ' Section 3 - This is the section that resets lstGTC
    Set db = CurrentDb
    strSQL = "SELECT tblItems.GTC" & Chr(10) & "FROM tblItems" & Chr(10) & "GROUP BY tblItems.GTC" & Chr(10) & "ORDER BY tblItems.GTC;"
    qryName = "qrylstGTC"
    Set qdf = db.CreateQueryDef(qryName, strSQL)
    Forms!frmDataSelector2!lstGTC.RowSource = qryName
    ' End Section 3
    ' Section 4 - This is the section that resets the lstWorkCenter
    strSQL = "SELECT tblRoutings.WorkCenter" & Chr(10) & "FROM tblItems INNER JOIN tblRoutings ON tblItems.Item = tblRoutings.Item" & Chr(10)
    strSQL = strSQL & "GROUP BY tblRoutings.WorkCenter" & Chr(10) & "ORDER BY tblRoutings.WorkCenter;"
    qryName = "qrylstWorkCenter"
    Set qdf = db.CreateQueryDef(qryName, strSQL)
    Forms!frmDataSelector2!lstWorkCenter.RowSource = qryName
    ' End Section 4
    ' Section 5 - This section resets lstOpType
    strSQL = "SELECT tblWorkCenters.GeneralDesc" & Chr(10) & "FROM (tblItems INNER JOIN tblRoutings ON tblItems.Item = tblRoutings.Item) "
    strSQL = strSQL & "INNER JOIN tblWorkCenters On tblRoutings.WorkCenter = tblWorkCenters.WorkCenter" & Chr(10)
    strSQL = strSQL & "GROUP BY tblWorkCenters.GeneralDesc" & Chr(10) & "ORDER BY tblWorkCenters.GeneralDesc;"
    qryName = "qrylstOpType"
    Set qdf = db.CreateQueryDef(qryName, strSQL)
    Forms!frmDataSelector2!lstOpType.RowSource = qryName
    ' End Section 5
    '  Section 6 - This section handles the error handling
        Exit Sub
        If Err.Number = 3012 Then
        DoCmd.DeleteObject acQuery, qryName
        MsgBox Err.Number & " - " & Err.Description & " - " & Err.HelpFile
        Resume Exit_BuildQry
        End If
    ' End Section 6
    End Sub

    Now, who has suggestions on my other thread??!!

    Thanks Again,

Posting Permissions

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