delete all rows in a table

R

Rivers

can someone please advise me on the way i can delete all rows in my table
called "00 1-1 booked" i tried the delete method in VB but to no avail is it
possible to call a delete method from vb. i still want the structure to
survive but the recdords to be deleted.

thanks
 
F

fredg

can someone please advise me on the way i can delete all rows in my table
called "00 1-1 booked" i tried the delete method in VB but to no avail is it
possible to call a delete method from vb. i still want the structure to
survive but the recdords to be deleted.

thanks

Is it a one time deal?
Just open the table. Select all the records by (clicking in the little
square in the left hand corner where the gray field names meets the
record selectors).
Press the Delete key.

You can delete all records using a delete query,
or
you can use VBA code:

CurrentDb.Execute 'Delete * from TableName;", dbFailOnError

All the date will be deleted, but the fields and properties will be
untouched.
 
J

Jeanette Cunningham

Rivers,
referential integrity can prevent records from being deleted.
If this is your situation, delete records from any child tables before you
try to delete records from any parent table.

Jeanette Cunningham
 
R

Rivers

I tried the command already but this did not work is there another way?

Jeanette Cunningham said:
Rivers,
referential integrity can prevent records from being deleted.
If this is your situation, delete records from any child tables before you
try to delete records from any parent table.

Jeanette Cunningham
 
R

Rivers

TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from TableName;", dbFailOnError

this command doesnt work what am i doing wrong please help

thanks

Rivers said:
I tried the command already but this did not work is there another way?
 
R

Rick Brandt

Rivers said:
TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from TableName;", dbFailOnError

this command doesnt work what am i doing wrong please help

The variable cannot be inside the quotes or else the query will actually
looking for a table named "TableName".

TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError
 
R

Rick Brandt

Rick said:
The variable cannot be inside the quotes or else the query will
actually looking for a table named "TableName".

TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError

Sorry, I completely missed the ramifications of this (really horrible) table
name on the process. It will of course need to have square brackets around
it because of the spaces and the fact that the name begins with a digit.

TableName = "[00 1-1 booked]"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError
 
B

Bob Quintal

TableName = "[00 1-1 booked]"
CurrentDb.Execute "Delete * From" & TableName, dbFailOnError

tried this but it asks for a parameter as it is missing
if that's pasted from your module, you are missing a space between
from and "

Rick Brandt said:
Rick said:
Rivers wrote:
TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from TableName;", dbFailOnError

this command doesnt work what am i doing wrong please help

The variable cannot be inside the quotes or else the query will
actually looking for a table named "TableName".

TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError

Sorry, I completely missed the ramifications of this (really
horrible) table name on the process. It will of course need to
have square brackets around it because of the spaces and the fact
that the name begins with a digit.

TableName = "[00 1-1 booked]"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError
 
R

Rivers

TableName = "[00 1-1 booked]"
CurrentDb.Execute "Delete * From" & TableName, dbFailOnError

tried this but it asks for a parameter as it is missing

Rick Brandt said:
Rick said:
The variable cannot be inside the quotes or else the query will
actually looking for a table named "TableName".

TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError

Sorry, I completely missed the ramifications of this (really horrible) table
name on the process. It will of course need to have square brackets around
it because of the spaces and the fact that the name begins with a digit.

TableName = "[00 1-1 booked]"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError
 
F

fredg

TableName = "[00 1-1 booked]"
CurrentDb.Execute "Delete * From" & TableName, dbFailOnError

tried this but it asks for a parameter as it is missing

Rick Brandt said:
Rick said:
Rivers wrote:
TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from TableName;", dbFailOnError

this command doesnt work what am i doing wrong please help

The variable cannot be inside the quotes or else the query will
actually looking for a table named "TableName".

TableName = "00 1-1 booked"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError

Sorry, I completely missed the ramifications of this (really horrible) table
name on the process. It will of course need to have square brackets around
it because of the spaces and the fact that the name begins with a digit.

TableName = "[00 1-1 booked]"
CurrentDb.Execute " Delete * from " & TableName, dbFailOnError

When replying to a question many times we use generic names, such as
YourTable, MyTable, FormName, ControlName, etc.
You're supposed to replace those generic names with your actual object
names

Why are you placing the table name in a variable?
Substituting your table name for the generic YourTable, this works for
me:

CurrentDb.Execute "Delete * from [00 1-1 booked];", dbFailOnError
 

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