Clear button for multiple combo boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chansen
    New Member
    • Mar 2007
    • 2

    Clear button for multiple combo boxes

    I have a form with mulitple combo boxes that populates criteria in a query. I want to add a button to clear the selections in all of the combo boxes. What code do I use?

    Thanks!
  • KiwiGenie
    New Member
    • Mar 2007
    • 41

    #2
    This is what I have used:
    Code:
    Private Sub CommandClear_Click()
    Me.FiltRecName = Null
    Me.FiltCat = Null
    Me.FiltCost = Null
    Me.FiltIng1 = Null
    Me.FiltIng2 = Null
    End Sub
    Hope it helps :)

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by Chansen
      I have a form with mulitple combo boxes that populates criteria in a query. I want to add a button to clear the selections in all of the combo boxes. What code do I use?

      Thanks!
      Code:
      Dim ctl As Control
      
      For Each ctl In Me.Controls
        If ctl.ControlType = acComboBox Then
          ctl.Value = Null
        End If
      Next

      Comment

      • KiwiGenie
        New Member
        • Mar 2007
        • 41

        #4
        Thanks for showing a better way ADezii, my way works but yours is better. Can I do this:
        Code:
        Dim ctl As Control
        
        For Each ctl In Me.Controls
          If ctl.ControlType = acComboBox or ctl.ControlType = acTextBox Then
            ctl.Value = Null
          End If
        Next

        Comment

        • Chansen
          New Member
          • Mar 2007
          • 2

          #5
          Thanks it works great!! =)

          Comment

          Working...