A very simple solution to clear MS-Access '97 and 2000 tables:
Create a form with a combobox called "boxTables" and a button called "btnClearTable", then add the next code to the form:
Option Compare Database
Private Sub Form_Activate()
[boxTables].RowSourceType = "Value List"
For Each Item In Application.CurrentDb.tabledefs
[boxTables].RowSource = [boxTables].RowSource & ";" & Item.Name
Next
End Sub
Private Sub btnClearTable_Click()
Dim strSQL As String
For Each Item In Application.CurrentDb.tabledefs
DoCmd.SetWarnings warningsoff
If Item.Name = [boxTables].Value Then
strSQL = "DELETE " & [boxTables].Value & ".* FROM " & _
[boxTables].Value & ";"
DoCmd.RunSQL strSQL
End If
DoCmd.SetWarnings warningson
Next
End Sub
BE CAREFUL! This thing will delete everything in th table so be sure to pick the right table name from the combobox...
I would recommend including an "are-u-sure" messagebox...
If anyone has a better solution, please let me know.
Regards,
Thamar.
Enter your message below
Sign in or Join us (it's free).