How to clear a back end table that is used as a form control source

Posted on 2012-08-30
Last Modified: 2012-08-31
I have a MS Access form that uses a table as the control source.  I would like to create a button so when the user click it ~ it will delete the contents of the table getting it ready for new entry.  I don't need to save the table contents.
Question by:deefel
    LVL 56

    Accepted Solution

    1. Add your button to the form.

    2. n the proeprty sheet, find the OnClick event and enter "[Event procedure]" and click the builder button (...) off to the right.  A code window will open up.

    3. In the code window, enter:

      CurrentDB().Execute "DELETE * FROM <table name>"

      in the above replace <table name> with the actual table name.

    Close the code windwo and give it a try.

    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    <No Points wanted, just some extra info>

    <I don't need to save the table contents. >
    OK, but a user can always click the "Delete" button by mistake....
    ...Thus clearing the table before it should be cleared.
    (note that in Access, once a record is deleted, it cannot simply be recovered with an UNDO...)

    I always throw code like this around any "destructive" code

    If msgbox("Clear all records?",vbyesno+vbquestion)=ybNo then
        exit sub
        'Your Delete code here
    end if



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now