none
Using a button to clear all fields on a form RRS feed

  • Question

  •  

    Good evening everyone!

    I have a form in Access 2010 and the controls are bounded to a database. I have a piece of code attached to a button that will undo or clear the entries in the form. However, this button or code only works for data I have entered but not saved. So lets say I search my database and get a record and decide to clear the result, clicking the button does not clear the form.

    Is it at all possible to use this same button to undo entries but also clear a record after searching for a record.
    How can I use this button to clear the search results.

    Here is my code:


    Private Sub CommandUndo_Click()
    Me.Undo
    End Sub

    I am using Me.undo because it works better in my situation, if I use command Undo, it give me an error when I click the button twice.


    BL

    Monday, October 3, 2011 10:28 PM

Answers

  • Hi BL,

    For the Search Form, its better to use an Unbound Form, and then show the results of the Search for example in a Subform.

    For a nice example, take a look at this thread:
    http://allenbrowne.com/ser-62.html

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Monday, October 3, 2011 11:17 PM
    Moderator

All replies

  • Hi BL,

    For the Search Form, its better to use an Unbound Form, and then show the results of the Search for example in a Subform.

    For a nice example, take a look at this thread:
    http://allenbrowne.com/ser-62.html

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Monday, October 3, 2011 11:17 PM
    Moderator
  • Hi BL,

    For the Search Form, its better to use an Unbound Form, and then show the results of the Search for example in a Subform.

    For a nice example, take a look at this thread:
    http://allenbrowne.com/ser-62.html

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    I wasn't intending to build a search or sub form, but maybe I'll look into it.

    Thank you!

     

    BL

    Monday, October 3, 2011 11:28 PM
  • Hi BL,

    What are you exactly looking for, just clear all entries of a Textbox in a Form?

     

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, October 4, 2011 12:11 AM
    Moderator
  • Hi BL,

    What are you exactly looking for, just clear all entries of a Textbox in a Form?

     

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Yes, I have a button on my form the pops up the Access search window, when I find a record, it populates the form, which is what I want. So I want to be able to click this button to clear the results of the search.

    BL
    Tuesday, October 4, 2011 12:14 AM
  • Do you mean erase the content for the Access Search window, or the Form where the content is Found via the Access Search?

    I think you don't want to erase all the content for that particular record I assume?

     

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, October 4, 2011 12:18 AM
    Moderator
  • Do you mean erase the content for the Access Search window, or the Form where the content is Found via the Access Search?

    I think you don't want to erase all the content for that particular record I assume?

     

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    No, let me explain further and thanks for you patience. I have a form that I use to enter data into a database. I placed a button on the form and named it CommandSearch. So when I click this button a search within Access pops up, with the find button. I type the name I am going to search for in this search box. If the record is available, it populates my form. Now how do I get rid of this record to bring the form back to blank? I do not want to delete the record, I simply want to clear the form fields, not delete the record from the database.

    Hope that helps.

    Thanks again.

    BL
    Tuesday, October 4, 2011 12:26 AM
  • Hi BL,

    Okay, I understand what you are trying to do, but this Form you use to enter data into your database is bound to a Table?

    So in my understanding if you do the search, and it will find the 'content' you are looking for, it will go to that record and whill show that record in your Form. So far so good, but when you say you want that results shown in your Form to be blank, is in other words saying your delete all the content in that particular record, which will be saved after you are closing the Form as it is bound to your Table. The result is a record saved in your Table with blank fields. So I believe that's not what you are after. Unless I miss something on how your Form is populated.


    Because I don't want to offer you a solution, which will erase your data from your Table.

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, October 4, 2011 12:34 AM
    Moderator
  • Hi BL,

    Okay, I understand what you are trying to do, but this Form you use to enter data into your database is bound to a Table?

    So in my understanding if you do the search, and it will find the 'content' you are looking for, it will go to that record and whill show that record in your Form. So far so good, but when you say you want that results shown in your Form to be blank, is in other words saying your delete all the content in that particular record, which will be saved after you are closing the Form as it is bound to your Table. The result is a record saved in your Table with blank fields. So I believe that's not what you are after. Unless I miss something on how your Form is populated.


    Because I don't want to offer you a solution, which will erase your data from your Table.

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Good point, but I am not trying to delete the record, the record in the form is a search result, all I need to do is clear the form. In html, it will be Reset. The form is bound to a database/tables, the search result is displayed from the database to the form, again I want to clear the form.

    Thanks again!

    BL
    Tuesday, October 4, 2011 12:39 AM
  • Hi BL,

    I don't think using a Form bound to a Table will work, to be honest, because of the reason I described above.

    I think you would be better of using the example as mentioned in the link I gave you. This is an example, there are other ways to do the same thing.

    As long as you only want to show search results, use an Unbound Form, and populate these with your results. In this way you can clear your search results without doing any changes to the content in your Tables.

    Unless your purpose of your search is finding the records, and also need to Edit the content.

    You might then use a Form Filter instead, which basicly Filter the Form based on the Search, and only narrow down your Bound Form to the Records which has the 'content' searched for.

     

    Hope this helps,

     

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, October 4, 2011 12:50 AM
    Moderator
  • Hi BL,

    I don't think using a Form bound to a Table will work, to be honest, because of the reason I described above.

    I think you would be better of using the example as mentioned in the link I gave you. This is an example, there are other ways to do the same thing.

    As long as you only want to show search results, use an Unbound Form, and populate these with your results. In this way you can clear your search results without doing any changes to the content in your Tables.

    Unless your purpose of your search is finding the records, and also need to Edit the content.

    You might then use a Form Filter instead, which basicly Filter the Form based on the Search, and only narrow down your Bound Form to the Records which has the 'content' searched for.

     

    Hope this helps,

     

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Yep, I agree with you, I am going to hit the books, I will also go to the link you provided and see what I can do.

    Thanks for your time sir!

    BL
    Tuesday, October 4, 2011 12:54 AM
  • Hi BL 

    I'm looking for code that clears the form whether data is saved or not.

    Friday, May 19, 2017 9:56 AM