VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Deletes all tables in an Access database (hidden system tables are handled correctly)

by VB-Kung-Fu (19 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 9th December 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Deletes all tables in an Access database (hidden system tables are handled correctly)

Rate Deletes all tables in an Access database (hidden system tables are handled correctly)



'delete tables from

'*******************************************************
'DropTables:
'   Drops all tables in the database.
'*******************************************************
Public Sub DropTables()

Dim rs As DAO.Recordset, tdf As TableDef

If MsgBox("Warning! All tables will be deleted.", vbYesNo, "Database = " & CurrentDb.Name) = vbNo Then
    Exit Sub
End If

For Each tdf In CurrentDb.TableDefs
    If IsSystemTable(tdf.Name) = False Then
       Call CurrentDb.Execute("DROP TABLE " & tdf.Name)
    End If
Next
End Sub

'*******************************************************
'IsSystemTable
'   Checks if the named table is a system table.
'   System tables begin with "MSys" and sometimes
'   with "~sq_" when the database hasnt been compacted.
'*******************************************************
Public Function IsSystemTable(TblName As String) As Boolean
IsSystemTable = IIf(InStr(1, "MSys ~sq_", Left(TblName, 4), vbTextCompare) <> 0, True, False)
End Function

Download this snippet    Add to My Saved Code

Deletes all tables in an Access database (hidden system tables are handled correctly) Comments

No comments have been posted about Deletes all tables in an Access database (hidden system tables are handled correctly). Why not be the first to post a comment about Deletes all tables in an Access database (hidden system tables are handled correctly).

Post your comment

Subject:
Message:
0/1000 characters