@ Tom,
I am in agreement with Micron re: "Things can go real bad in a split second". You have been warned...but it seems you are going to go ahead anyway.
Originally Posted by
skydivetom
I'll look at the provided link and hopefully I can come up w/ a solution.
I read the link post #37 (explanation at the bottom). I'm not sure about your use of DELETE or DROP. DROP removes TABLES. DELETE removes records in a table.
Try this on a COPY of your dB...... again a COPY of the dB.
Code:
Option Compare Database
Option Explicit
Public Sub DropTables()
Dim d As DAO.Database
Dim r As DAO.Recordset
Dim sSQL As String
Dim k As Integer
Dim RC As Integer
Dim Msg, Style, Title, Response, MyString
Set d = CurrentDb
sSQL = "SELECT [00_DeleteTables].TableName"
sSQL = sSQL & " FROM 00_DeleteTables"
sSQL = sSQL & " WHERE [00_DeleteTables].Delete = True;"
Set r = d.OpenRecordset(sSQL)
If r.BOF And r.EOF Then
MsgBox "No tables selected to DROP"
Else
r.MoveLast
r.MoveFirst
RC = r.RecordCount
Msg = "Clicking YES will DROP " & RC & " tables."
Msg = Msg & vbCrLf
Msg = Msg & " Are sure you want to continue?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "DROP Tables" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Msg = "Last Chance - Are you SURE??"
Msg = Msg & vbCrLf
Msg = Msg & " Are sure you want to continue?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "DROP Tables - Last chance" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Do While Not r.EOF
k = k + 1
'drop tables
sSQL = "DROP TABLE " & r.Fields(0) & ";"
Debug.Print sSQL
d.Execute sSQL, dbFailOnError
'--- delete record from [00_DeleteTables] ---
' sSQL = "Delete * FROM [00_DeleteTables]"
' sSQL = sSQL & " WHERE TableName = '" & r.Fields(0) & "'"
'--- OR set the DELETED check box to FALSE in [00_DeleteTables] ---
sSQL = "UPDATE 00_DeleteTables SET [Delete] = False"
sSQL = sSQL & " WHERE TableName = '" & r.Fields(0) & "';"
d.Execute sSQL, dbFailOnError
r.MoveNext
Loop
MsgBox "Done!" & vbCrLf & "Dropped " & k & " tables"
End If
End If
End If
'clean up
On Error Resume Next
r.Close
Set r = Nothing
Set d = Nothing
End Sub
You have been warned!!!!
Edit: Forgot to mention you have a field "Deleted" in table 00_DeleteTables.
I am hoping you do not have a production (real) table with a field named "DELETED" as "DELETED" is a reserved word in Access.