TableQuery




Dim DB As Database
Private Function ExistsTableQuery(TName As String) As Boolean
Dim Test As String
On Error Resume Next
' See if the name is in the Tables collection:

Test = db.TableDefs(TName).Name
If Err <> NameNotInCollection Then
ExistsTableQuery = True
' Reset the error variable:

Err = 0
' See if the name is in the Queries collection:

Test = db.QueryDefs(TName$).Name
If Err <> NameNotInCollection Then
ExistsTableQuery = True
End If
End If
End Function
'________________________________________________________


'5. Add the following code to the Form1_Click procedure:

Public Sub Form1_Click ()
Set DB = DBEngine.Workspaces(0).Opendatabase("Biblio.mdb")
Print "BadTable " ;IIF (ExistsTableQuery("BadTableName"), _
"does", "doesn't"); " exist."
Print "Authors " ;IIF (ExistsTableQuery("Authors"), _
"does", "doesn't"); " exist."
End Sub

'3. Start the program by choosing Start from the Run menu or by pressing the

' F5 key. The program correctly prints:

BadTable doesn't exist.
Authors does exist.










( tablequery.html )- by Paolo Puglisi - Modifica del 17/12/2023