1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: MS Access 2007: Creating a 'Clear All Form Fields' button that actually works

Discussion in 'Business Applications' started by witakr, Jun 5, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. witakr

    witakr Thread Starter

    Joined:
    Dec 9, 2006
    Messages:
    121
    Hey there folks! I had an issue with clearing fields and that was resolved but the resolution presented another problem. A problem which I have been unsuccessful in resolving on my own.

    I have tried about 3 different methods using command buttons and the VBE but nothing is working.

    I need 2 buttons: One to clear all form fields and one to clear all form fields then close the form.

    I know how to make a button to close a form but I am unable to make it clear the fields prior to closing. I have also been unsuccessful in creating a button to simply clear the form fields.

    Any help is greatly appreciated.

    Jason
     
  2. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    witakr, why on earth do you want to clear the fields before closing the Form?
     
  3. witakr

    witakr Thread Starter

    Joined:
    Dec 9, 2006
    Messages:
    121
    Because I noticed that if the user types something in one of the fields and leaves another fields blank and if that blank field happens to be a required field then it throws an error when I try to close saying the record will not be saved because not all required fields were filled. I want to avoid that. Unless there is a better way to handle it.

    I still need a button that only clears all field too, though
     
  4. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    In the event of a "partial" record being entered you can use the "Undo" function to clear the whole record. However if you have an Autonumber key field it will have been incremented and it will leave a gap in the numbers.
    So just clearing the fields would not overcome the "required field" errror, the record has to be undone.
    But how do you know that the user wants to clear the record, shouldn't they finish entering the data?
     
  5. witakr

    witakr Thread Starter

    Joined:
    Dec 9, 2006
    Messages:
    121
    I am using an UNDO button but what I am talking about occurs before the record is saved/created. For example: Textbox1, Textbox2 and Textbox3 are requiered. The user begins typing in Textbox1 then realizes he doesn't need to create the record so the user stops entering the data in the fields. Now when the user tries to close the form he gets an error message indicating that he needs to enter something into the required fields before proceeding. But the user doesn't want to add a new record now but the form wont let him close the form without entering data in all the fields. Make sense? Clear as mud?

    Even if you delete the data from all fields it will still throw this same error. How do I stop that from happening?

    EDIT: Oh i forgot to mention.. I'm using unique identifiers as my primary keys so i dont use autonumber at all in the db
     
  6. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    That is what the Undo command is for. It does the same as the user pressing the Esc key twice to clear out a partial reecord.
    You could remove the "required" property from the table fields and replace it with a VBA check, then if the user wants to close the form when a partial entry is made you can ask them if they are sure and then close the form.
     
  7. witakr

    witakr Thread Starter

    Joined:
    Dec 9, 2006
    Messages:
    121
    I know the solution. You made me try something and when I did it fixed it.


    How do I replicate the 'Esc' key with a control button?
     
  8. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    That is the Undo command.
     
  9. witakr

    witakr Thread Starter

    Joined:
    Dec 9, 2006
    Messages:
    121
    You sir are my hero. You have solved about all my issues I have been struggling with for the last few weeks. You are awesome. Thank you for your help.

    I never realized that the thing I needed most was sitting right there under my nose the whole time. Thank you.
     
  10. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    My pleasure.
     
  11. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/927241

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice