Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete all records in a table quickly.

Access Version or Conversion

Delete all records in a table quickly.

by  Michael42  Posted    (Edited  )
Sub deleteAllRecords()
On Error GoTo ErrorHandler

Dim oDB As Database, iResult As Integer
Set oDB = OpenDatabase(App.Path & "\mydbfile.mdb")

[color green]'Confirm[/color]
iResult = MsgBox("Are you sure you want to delete ALL records?", vbOKCancel + vbCritical + vbDefaultButton2, "Delete All Records?")
If iResult = vbOK Then
Screen.MousePointer = vbHourglass
DoEvents
DoEvents
DoEvents

[color green]'Delete Operation[/color]
oDB.Execute "DELETE * FROM main"
DoEvents

Screen.MousePointer = vbDefault
MsgBox "Delete Operation Completed"
End If

On Error GoTo 0
Exit Sub

ErrorHandler:
Screen.MousePointer = vbDefault
MsgBox "Error: " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbExclamation, "Error (deleteAllRecords)"

End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top