Question : Why does using TableDefs cause table to be used/locked?

I have a the attached functions which allow me to easily delete a table if it needs it.  When I use the first function (erasetable) there are no problems.  But when I use the blnCheckTable function to see if the table exists, when I do go to delete the table I get a runtime error 3211.  What is really strange is I don't get this error everywhere in the database.  So, is there something I can do to unlock the table, perhaps closeout the tabledefs reference?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
'**************Functions used to erase tables*****************Start
Function EraseTable(strTableName As String)
    'Delete the table pased into the function
    If blnCheckTable(strTableName) = True Then DoCmd.DeleteObject acTable, strTableName
End Function

Function blnCheckTable(strTableName As String) As Boolean
    'check to ensure the table name exists in the table definitions
    'if any error occurs then check table = false
On Error GoTo subexit:
 
    If CurrentDb.TableDefs(strTableName).Name = strTableName Then
        blnCheckTable = True
    End If

subexit:
End Function
'**************Functions used to erase tables*****************End

Answer : Why does using TableDefs cause table to be used/locked?

you can also, use this simple code to delete the table

Function EraseTable(strTableName As String)
    'Delete the table pased into the function
on error resume next
     DoCmd.DeleteObject acTable, strTableName
End Function

Random Solutions  
 
programming4us programming4us