We use the below function to check if a table exists. I was curious if we could modify it to check for a table or query, or if a secondary function would have to be created to check for a query
Code:
Public Function TableExists(strName As String) As Boolean
On Error GoTo HandleErr
Dim Db As DAO.Database, tDef As DAO.TableDef
Set Db = CurrentDb
TableExists = False
For Each tDef In Db.TableDefs
If tDef.Name = strName Then
TableExists = True
Exit For
End If
Next tDef
ExitFunction:
Db.Close
Set Db = Nothing
Exit Function
HandleErr:
TableExists = False
Resume ExitFunction
End Function
And we call it like such
Code:
tableArray = Array("ESR", "NAC", "_LMNO")
'Iterating the array to pass each one individually to the Delete function
For amx = 0 To UBound(tableArray)
If TableExists(amx) Then
With Db.TableDefs
.Delete amx
.Refresh
End With
End If
Next
Could the same function be adapted to check for a query as well?