Delete all records in a table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a table that is used for usage data, and from time to time, I want to
clear it out, using a button on a form. What would the code be to delete all
of the records in a table, but still leave the table there?

Many Thanks,

Darren
 
create a Delete Query that says "DELETE FROM YourTableName"

thats it!
 
If you don't want the system warning to popup telling you that you're about
to delete records, try this for your button:

'********code start*********
Private Sub cmdDeleteRecords_Click()
Dim strSQL As String

On Error GoTo Err_Delete
If MsgBox("Do you really want to delete all records?", _
vbExclamation + vbYesNo, "Delete Records?") = vbNo Then
Exit Sub
Else
strSQL = "Delete From TheTableName"
CurrentDb.Execute strSQL, dbFailOnError
MsgBox "Records have been deleted", , "Success"
End If

Exit_Delete:
Exit Sub
Err_Delete:
MsgBox "Error " & Err.Number & ": " & Err.Description, ,
"cmdDeleteRecords_Click"
Resume Exit_Delete
End Sub
'*******code end***********
 

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

Back
Top