Results 1 to 8 of 8
  1. #1
    Join Date
    May 2002
    Posts
    46

    Unanswered: Reset form controls to default values

    I wanted to include a "Reset" button on my form that would clear out all existing calculated & user-entered values in the various textboxes and combos on my form to their original default values that are set in their respective properties.

    Is there a quick way to do this or will I need to cycle through all the controls & reset them via code?

    Thanks,
    Brian

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I think your stuck with:

    txtBox1 = Null
    txtBox2=Null
    cmbBox3 = Null
    txtBox4=0

    There isn't a magic "ClearForm" function.

    You could move to a new record, but that would only clear the bound controls. You'd still have to clear the calculated and unbound controls
    with VB.
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2010
    Posts
    9
    any tips on how to "reset" buttons? once a button has been pushed on a form is stays in a "pushed" / or activated / state and cannot be reactivated without closing the form and reopening it.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try something like:
    Code:
        Dim ctl As Control
        
        For Each ctl In Me.Controls
            Select Case ctl.ControlType
                Case acComboBox, acListBox, acOptionGroup, acTextBox    ' add other types if necessary
                    ctl.Value = ctl.DefaultValue
            End Select
        Next
    Have a nice day!

  5. #5
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    You could use the Tag property of the controls to store the default values that you want and then use a loop to reset everything like:

    Code:
        For Each varControl In Me.Controls
        
            If varControl.ControlType = acTextBox Or varControl.ControlType = acLabel Then
                    
                    varControl.Value = varContol.Tag
                    
                End If
                
            End If
                
        Next varControl
    In this example I only use the Tag property on labels and text boxes.

  6. #6
    Join Date
    Aug 2009
    Location
    Up Nort' Wi
    Posts
    140
    Or use a command button versus a toggle button.

    Sam
    Good, fast, cheap...Pick 2.

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Me.Toggle_X.Value = False
    Have a nice day!

  8. #8
    Join Date
    Jul 2010
    Posts
    1
    Assuming all of your default values are text this will work if you add something to remove the quotes that will be placed around them.

    Code:
     
    Sub ClearForm(Test As Form)
          Dim Ctl As Control
          On Error Resume Next
          For Each Ctl In Test.Controls
                Ctl.Value = Ctl.DefaultValue
          Next Ctl
    End Sub

Posting Permissions

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