By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Clearing table

P: 21
Is there a clever way of enabling a user to clear all data from a table by simply clicking a button on a form?
At present I'm doing it a rather clumsy and unreliable way using macros to -
Transferdatabase (importing to a new temporary table)
Transferdatabase (exporting the structure back)
Deleteobject (deleting temporary table)
There must be a better way!
Thanks.
Kev
Nov 20 '08 #1
Share this Question
Share on Google+
5 Replies


DonRayner
Expert 100+
P: 489
Is there a clever way of enabling a user to clear all data from a table by simply clicking a button on a form?
At present I'm doing it a rather clumsy and unreliable way using macros to -
Transferdatabase (importing to a new temporary table)
Transferdatabase (exporting the structure back)
Deleteobject (deleting temporary table)
There must be a better way!
Thanks.
Kev
Why not try a delete query
Nov 20 '08 #2

P: 21
Thanks for the reply.
Could you expand a bit on what you mean please?
(I'm very new to this!)
Thanks.
Kev
Nov 20 '08 #3

DonRayner
Expert 100+
P: 489
Thanks for the reply.
Could you expand a bit on what you mean please?
(I'm very new to this!)
Thanks.
Kev
In the On Click event for your button you need to put something like the following. Replace MyTable with the name of the table you want to delete all the records from.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings = False
  2. Dim SqlStr as string
  3. SqlStr = "Delete[MyTable].* From [MyTable]"
  4. DoCmd.RunSql SqlStr
  5. DoCmd.SetWarnings = True
  6.  
If you are not comfortable with VBA then you will have to create the delete query using the access query builder. Just make it like you were creating a normal select query. Then before you save it you need to select Delete Query from the Query menu on the menu bar and then save it. You can then use whatever means your comfortable with to run the query.
Nov 20 '08 #4

P: 21
Many thanks.
Got there eventually using your script.
Very grateful!
Kev
Nov 20 '08 #5

DonRayner
Expert 100+
P: 489
Many thanks.
Got there eventually using your script.
Very grateful!
Kev
Glad I could be of some help.
Nov 20 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.