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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting tables from code

Status
Not open for further replies.

pullingteeth

Programmer
Sep 26, 2003
128
US
I maintain a "development" version of a "production" database. Every time I release it I first delete all of the tables in development, import the tables from production (with current data), build an MDE file, and move it to the production location.

I'm working on automating at least the first two stages; so far I have (for deleting all tables):

Code:
Private Sub Command3_Click()
    Dim tname As String, tname2 As String
    Dim i As Integer
    
    ' authenticate that user is qualified to do this
    
    For i = 0 To (CurrentDb.Relations.count - 1)
        tname = CurrentDb.Relations(i).Table
        tname2 = CurrentDb.Relations(i).ForeignTable
        If (Not isSysTable(tname)) And (Not isSysTable(tname2)) Then
            ' XXX somehow delete it
        End If
    Next i
    
    For i = 0 To (CurrentDb.TableDefs.count - 1)
        tname = CurrentDb.TableDefs(i)
        If Len(tname) > 0 And (Not isSysTable(i)) Then
            DoCmd.DeleteObject acTable, tname
        End If
    Next i
End Sub

Private Function isSysTable(tname As String) As Boolean
    isSysTable = (InStr(1, tname, "MSys") <> 1)
End Function

This code is non-functional, however, as Access demands that I delete the relationships first, and while I can find all of the relationships, I cannot figure out how to delete them (see the XXX, in the code above).

Any thoughts?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top