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
 
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***********
 
Back
Top