Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying to clear my unbound form with an onClick event. Partially working

    I got this bit of code online, and it works fine to clear my combo boxes.. I changed a few things to try to get it to clear a couple text boxes on the form as well.. however my improvisation did not work. Here is the original code
    :------------------------------------------------
    Private Sub cmdClearCombos_Click()
    ' Resets ALL combobox values in the current form to null.

    Dim ctl As Control

    For Each ctl In Me.Controls
    If TypeOf ctl Is ComboBox Then
    ctl.Value = Null

    End If
    Next

    End Sub

    -----------------------------------------------------

    I tried adding another IF/Then after that one to clear TextBox,
    got errors.

    Then I tried to add an OR, such as "If typeof ctl is ComboBox or TextBox Then"
    this also didnt work, although it did still clear my combo boxes and didnt error.

    There is probably a really ez way to do this. Any tips? Best Regards...................Karl

  2. #2
    New Lounger
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok.. I kept looking and found the answer.. for anybody who might benefit from it.. here is the code that worked. I totally, sorta get it now.


    Private Sub cmdClearCombos_Click()
    Dim ctl As Control

    For Each ctl In Me.Controls
    Select Case ctl.ControlType
    Case acTextBox, acComboBox, acCheckBox
    ctl.Value = Null
    End Select
    Next ctl
    End Sub
    Last edited by Karl1971; 2011-12-21 at 15:18.

Posting Permissions

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