Creating a reset/clear button for a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Denielle
    New Member
    • May 2014
    • 17

    Creating a reset/clear button for a form

    Good Afternoon,

    I have been trying to figure this out for days. I have a search form in Access 2007 that is unbound with unbound text boxes. The submit button works great, but I am trying to creat a clear button so that the user can clear out their information at once instead of each individual field. My form name is SearchingForm and the text boxes are clientname, operatingstate, product. I have tried the following codes:

    Code:
    Private Sub resetbtn_Click()
    
    Me.Refresh
    
    End Sub
    also tried

    Code:
    Private Sub resetbtn_Click()
    
    Me.clientname = ""
    Me.operatingstate = ""
    Me.product = ""
    Me.Refresh
    
    End Sub
    Any help would be appreciated. I have not used Access or VB in years, so I am trying to relearn for work. Thanks
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    The refresh isn't needed. What happens with your second block of code? Do you get an error message or does it run and just not clear the fields?

    Comment

    • Denielle
      New Member
      • May 2014
      • 17

      #3
      Thank you for the quick response. On either block of code that I try it does nothing, just sits there. I have also tried the = Null instead of the = "". Just to clarify on the code that I listed it was not in there at the same time, that is code that I tried on two different attempts at trying to get it to work

      Comment

      • Luk3r
        Contributor
        • Jan 2014
        • 300

        #4
        So, your textboxes are named: clientname, operatingstate, and product?

        Comment

        • Denielle
          New Member
          • May 2014
          • 17

          #5
          Sorry for the delay. Yes the three text boxes are named the above. (no capitalization and no spaces).

          Comment

          • Luk3r
            Contributor
            • Jan 2014
            • 300

            #6
            Have you tried:
            Code:
            Me.buttonName.Value = ""

            Comment

            • Denielle
              New Member
              • May 2014
              • 17

              #7
              Yes, I have tried that as well and had the same response - nothing happened.

              Comment

              • Seth Schrock
                Recognized Expert Specialist
                • Dec 2010
                • 2965

                #8
                This makes me think that your code isn't running. Try typing STOP right before your code and then click your Clear button and see if the code stops at that line.

                Comment

                • Denielle
                  New Member
                  • May 2014
                  • 17

                  #9
                  Ok I just tried that, but I am not sure what it is suppose to do. I get the same result. I have the code open when I am clicking on the clear button and I see nothing happening. Thanks so much for all of the help with this. Here is the code that I have put in

                  Code:
                  
                  Private Sub resetbtn_Click()
                    
                  Stop
                  
                  Me.clientname = ""
                  Me.operatingstate = ""
                  Me.product = ""
                  
                  End Sub

                  Comment

                  • Seth Schrock
                    Recognized Expert Specialist
                    • Dec 2010
                    • 2965

                    #10
                    Ok, if the code was actually running, then the code would have stopped with your Stop line highlighted. Go to your Reset button's event list in the properties window. Click in the On Click event line and then click the ellipsis button. If it is attached to your code, it will take you to it. If not, then it will either take you to the code window and create a new event sub or it will ask you what you want to create. If the later, then choose the code option and click OK. That will then create a new event sub and then you can put your code in that one and delete your old one.

                    Comment

                    • Denielle
                      New Member
                      • May 2014
                      • 17

                      #11
                      I did that and it took me to my code.

                      Comment

                      • jimatqsi
                        Moderator Top Contributor
                        • Oct 2006
                        • 1290

                        #12
                        So it sounds like you wrote the code where it should have been, named as it should have been, but did not wire it up to the event. Now that you've done that, I suspect your click will work.

                        Jim

                        Comment

                        • Denielle
                          New Member
                          • May 2014
                          • 17

                          #13
                          You would think that would be the case, but it is still not working. I am not sure what I am doing incorrectly - but for some reason it is still not working.

                          Comment

                          • zmbd
                            Recognized Expert Moderator Expert
                            • Mar 2012
                            • 5501

                            #14
                            OP:2ndBlock:lin e7:Me.Refresh

                            change to

                            OP:2ndBlock:lin e7:Me.Repaint

                            post back results if any.

                            Comment

                            • Seth Schrock
                              Recognized Expert Specialist
                              • Dec 2010
                              • 2965

                              #15
                              Try going to Access Options>Trust Center>Trust Center Settings>Messag e Bar. Make sure that the option to Show the Message Bar in all applications when active content... has been blocked is selected. Then close the database and open it again. See if you get a yellow bar telling you that some content could be harmful and was disabled. If it does, click enable content and then try your button.

                              Comment

                              Working...