Tom,
I apologies, I didn't follow your threads from the start. I just jump in to answer about the "LK_" in code.
The difference of this function is the deletion of all tables in only one SQL execution.
"DROP TABLE Table1, Table2, Table3..."
Specifically, in our case:
Code:
'Drop all tables at once.
db.Execute "DROP TABLE " & strIN
I leave my last version and jump out, while the thread is indicated as solved.
Code:
Function DelTables(Optional ByVal fShowMessage As Boolean) As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strIN As String
Set db = CurrentDb
'Query the tables selected to drop.
Set rs = db.OpenRecordset("SELECT 'LK_' & [TableName] AS tName FROM 00_DeleteNonLOVs " _
& "WHERE [00_DeleteNonLOVs].Delete = True;")
On Error Resume Next
With rs
While Not .EOF
'Build a "list" with the existing tables to drop.
strIN = strIN & ", " & db.TableDefs(!tName).Name
.MoveNext
Wend
End With
rs.Close
Set rs = Nothing
On Error GoTo 0
strIN = Mid(strIN, 3)
If Len(strIN) Then
If MsgBox("Are you sure that you want to delete the selected tables?" _
, vbQuestion + vbYesNo + vbDefaultButton2, "Delete tables") = vbYes Then
'Drop all tables at once.
db.Execute "DROP TABLE " & strIN
'Return the count of droped tables via the RecordsAffected of db.
DelTables = db.RecordsAffected
db.TableDefs.Refresh
If fShowMessage Then
'Prepare the "list" of table names for WHERE clause.
'(Remove the 'LK_' and add single quotes on names.
strIN = Replace(Replace(strIN, "LK_", ""), ", ", "', '")
'Get the names of the tables that not found.
Set rs = db.OpenRecordset("SELECT 'LK_' & [TableName] AS tName FROM 00_DeleteNonLOVs " _
& "WHERE ([Delete]=True) AND (TableName NOT IN('" & strIN & "'))")
If rs.RecordCount Then
strIN = vbNullString
With rs
While Not .EOF
'Build a "list" with tables that not found.
strIN = strIN & vbCrLf & !tName
.MoveNext
Wend
MsgBox "The " & .RecordCount & " tables below not found:" & strIN, , "Delete tables"
End With
End If
rs.Close
Set rs = Nothing
End If
End If
Else
MsgBox "No tables selected to drop or does not exists. Review table [00_DeleteNonLOVs].", , "Delete tables"
End If
Set db = Nothing
End Function
You can choose to display the message about the skipped tables by the relevant optional argument. For example:
Cheers,
John