Clearing a table

B

Bob Parr

Is there an easy way to delete the contence of a table? I know I can go
through one at a time and delete records, but is that the only way?

Bob
 
S

Sandra Daigle

You can do this with a very simple query - just create a new query and click
view-SQL View and paste in the following, then change 'MyTable' to your
table name.

Delete * from MyTable;

As long as you haven't turned warnings off, it will prompt you to be sure
you really want to do this -
 
M

Marshall Barton

Bob said:
Is there an easy way to delete the contence of a table? I know I can go
through one at a time and delete records, but is that the only way?

You can click on the first record's record selector, hold
down the Shift key, scroll to the end of the table and click
on the last record's record selector, then hit the Delete
key.


Or you could run a DELETE query.
 
B

Bob Parr

I am sorry, I should have been clearer. I want to do this from VBA. and
What is a delete query?

Bob
 
M

Marshall Barton

Bob said:
I am sorry, I should have been clearer. I want to do this from VBA. and
What is a delete query?

A delete query is a query that deletes records in a table.

The VBA code to run a query could look something like:

DIm db As Database
Dim strSQL As String
Set db = CurrentDb()
strSQL = "DELETE * FROM thetable"
db.Execute strSQL, dbFailOnError
Set db = Nothing
--
Marsh
MVP [MS Access]


 
M

Marshall Barton

Sam said:
Or more simply...
DoCmd.RunSQL "DELETE * FROM tblMyTable"


Right!

It's just so rare that I want to see those are you sure
confirmation prompts that I almost always use the execute
method.
--
Marsh
MVP [MS Access]


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top