Library code snippets
Clearing tables in Access
This example shows you how to clean up tables in MS Access 2000. Please note: This only functions from within Access, since it uses the DoCmd function.
Option Compare Database
Private Sub Form_Activate()
DoCmd.Restore
[boxTables].RowSourceType = "Value List"
For Each Item In Application.CurrentDb.tabledefs
[boxTables].RowSource = [boxTables].RowSource &
";" & Item.Name
Next
End Sub
Create an empty form with two controls, a combobox named "boxTables" and a button named "btnClearTable", then add the next code:
Option Compare Database
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
Related articles
Related discussion
-
Problems with VBA User Forms on Excel
by Veritant (1 replies)
-
Problems with User Forms
by Uncle (1 replies)
-
Outlook VBA query
by James Crowley (1 replies)
-
problem with a progressbar : it dispears
by Uncle (1 replies)
-
Access, Calender dates, Strings and SQL
by Uncle (1 replies)
Events coming up
-
Jun
16
Code Generation 2009
Cambridge, United Kingdom
A developer event with a practical focus on helping people get to grips with code generation tools and technologies.
This thread is for discussions of Clearing tables in Access.