A reset Button for an Access Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abouddan
    New Member
    • Feb 2007
    • 42

    A reset Button for an Access Form

    Hi all

    I have an Access2000 form that contain many TextBoxes and a button. That button inserts the data in tables.
    How can reset all the TextBoxes automaticly without doing that one by one and manualy?

    Many thanks
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    You could try :
    Code:
    Call Me.Undo()
    ...from within your code.

    Comment

    • nico5038
      Recognized Expert Specialist
      • Nov 2006
      • 3080

      #3
      NeoPa is right, but the safest way is to use:

      If Me.Dirty then
      Me.Undo
      endif

      This will make sure no error message is triggered when performing an Undo on a form not yet filled.

      Nic;o)

      Comment

      • abouddan
        New Member
        • Feb 2007
        • 42

        #4
        Thanks for your support.
        I don't know why neither of the two sugestions works. I put a break point on
        "If Me.Dirty ..." and when the code run, he stoped on it and when hovering on "Me.Dirty" the result was "False" eventhought that all TextBoxes are filled.
        So I wrote this: "If Me.Dirty = False Then Me.Undo" . The code worked and the test was good but nothing happenned when running "Me.Undo" .
        I did some researches and I found this code and it worked very well.

        Code:
        Dim ctlC As Control
        For Each ctlC In Me.Controls
          If ctlC.ControlType = acTextBox Or ctlC.ControlType = acComboBox Then
            ctlC.Value = ""
          End If
        Next ctlC
        Last edited by NeoPa; Feb 20 '07, 10:39 AM. Reason: Tags

        Comment

        • nico5038
          Recognized Expert Specialist
          • Nov 2006
          • 3080

          #5
          The Me.Undo will only work for "bound" fields.
          When you have unbound fields you'll need indeed such a loop to force the field(s) to be initialized.
          It's however rare that you use unbound fields in Access as the bound fields are so easy to use :-)

          Nic;o)

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32662

            #6
            You're probably better off using Null rather than an empty string there. Null is typically used (and therefore more easily recognised) as an unset value.
            Code:
            Dim ctlC As Control
            For Each ctlC In Me.Controls
              If ctlC.ControlType = acTextBox _
              Or ctlC.ControlType = acComboBox Then ctlC = Null
            Next ctlC

            Comment

            Working...