• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 579
  • Last Modified:

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

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.
0
deefel
Asked:
deefel
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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>"
 Me.Requery


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


Close the code windwo and give it a try.

Jim.
0
 
Jeffrey CoachmanMIS LiasonCommented:
<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
else
    'Your Delete code here
end if

;-)

JeffCoachman
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now