I have about 59 tables that all start with "TOA_". I want to delete them in one fell swoop. But it's not working... When I run this code (below) nothing happens.
The strSQL (when pulled from the watch window and run in a query object) shows 59 tables with names starting with "TOA_"... yet when the cofde is being run, the recordset is showing no records...
So what's wrong with this code? Is this due to some issue with using MSysObjects? Or is my code wrong?
The strSQL (when pulled from the watch window and run in a query object) shows 59 tables with names starting with "TOA_"... yet when the cofde is being run, the recordset is showing no records...
So what's wrong with this code? Is this due to some issue with using MSysObjects? Or is my code wrong?
Public Sub DELETE_TOA_TABLES()
Dim strSQL As String
Dim strTable As String
Set cn = New ADODB.Connection
Set Db = CurrentDb
Set rs = New ADODB.Recordset
strSQL = "SELECT Name FROM MSysObjects WHERE MSysObjects.Name " & _
"Like " & Chr(34) & "TOA_*" & Chr(34) & " ;"
With rs
.activeconnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open (strSQL)
End With
If rs.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
strTable = rs!Name
DoCmd.RunSQL "DROP TABLE " & strTable
rs.MoveNext
Loop
End If
End Sub