• Home
  • Blog
  • Resume
  • Contact
  • Projects
  • Gallery
  • Amit’s Resume
  • About Nagpur
KEEP IN TOUCH

Access VBA: Delete tables from Access database

Jul18
2007
Leave a Comment Written by admin

If you want to delete all or some of the tables from your Access database, you can use this DAO approach. You would need a reference to Microsoft DAO 3.x object library. As shown in the example, you can use an array to store the table names, which you want to keep or delete.

Sub DelteTbls()
Dim sTblNm As String
Dim db As Database, tbldef As DAO.TableDef
Dim i As Integer, Arr As Variant

On Error GoTo DelteTbls_Error
‘You can use an array if you want to delete or not delete specific tables
‘Arr = Array(“Table1″,”Table2″,”Table3″)

Set db = CurrentDb() ‘Set the database object

‘Set the warnings off to suppress messages
DoCmd.SetWarnings False

‘For i = 0 To UBound(Arr)
    For Each tbldef In db.TableDefs
        ‘here you can use equal to or not equal to delete or keep specific tables
        ‘If Left(tbldef.Name, 4) = Arr(i) Then
        ‘Don’t delete System or temporary tables
        If Left(tbldef.Name, 4) “MSys” And Left(tbldef.Name, 1) “~” Then
              Debug.Print tbldef.Name
              sTblNm = tbldef.Name
              ‘Delete table
              DoCmd.DeleteObject acTable, sTblNm
        End If
    Next tbldef
‘Next i

MsgBox “Done!”

On Error GoTo 0

SmoothExit_DelteTbls:
    Set db = Nothing
    DoCmd.SetWarnings True
    Exit Sub

DelteTbls_Error:
    MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in procedure DelteTbls”
    Resume SmoothExit_DelteTbls
End Sub

Related posts:

  1. Description of the limitations for working with arrays in Excel 2000, Excel 2002, and Excel 2003
  2. Flip row or column
  3. Access VBA: Link all Dbase files from a folder
  4. Stack Columns of Data on one column
  5. Range Concatenation with a character
Posted in Access, Useful Procedures - Tagged Access, VBA
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Access VBA: Link all Dbase files from a folder
» Access VBA: Export Access tables using ODBC

No Comments Yet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Tags

Access Alt F8 Books boxplot cells charts count cursor dashboard data mining dbase design error excel excel functions export filter flip LaTex MS query Number Err ODBC pipes Press Alt F11 Public Sub python R random numbers Range Cells report scripting software sparklines SQL SQL server stack columns statistics stemming string tag cloud text mining UDF VBA visualization wildcard

Network

View Ashutosh Nandeshwar's profile on LinkedIn

Recent Comments

  • W. McNabb on The search key was not found in any record in Access
  • Manuel on The search key was not found in any record in Access
  • Wendy Naples on The search key was not found in any record in Access
  • larry on Access Export to Excel (2007)
  • Betty Chou on Projects

Related Posts

  1. Description of the limitations for working with arrays in Excel 2000, Excel 2002, and Excel 2003
  2. Flip row or column
  3. Access VBA: Link all Dbase files from a folder
  4. Stack Columns of Data on one column
  5. Range Concatenation with a character

EvoLve theme by Blogatize  •  Powered by WordPress nandeshwar.info