Check if table exists in a closed database

mukudu99

Registered User.
Local time
Today, 14:33
Joined
Dec 22, 2006
Messages
15
Hi Gurus
Is there a way to check if a table exists in another database without opening the database....
i am in C:\Data\Database1.mdb and i want to check if a table called Table1 exists in C:\Data\Database2.mdb without opening Database2.mdb

I know i could easily do this in the current db
Thanks
 
Simple Software Solutions

Code:
Function IsTableQuery(DbName As String, TName As String) As Integer

   Dim DB As dao.Database, Found As Integer, Test As String
   Const NAME_NOT_IN_COLLECTION = 3265

   ' Assume the table or query does not exist.
   Found = False

   ' Trap for any errors.
   On Error Resume Next

   ' If the database name is empty...
   If Trim$(DbName) = "" Then
      ' ...then set Db to the current Db.
      Set DB = CurrentDb()
   Else
      ' Otherwise, set Db to the specified open database.
      Set DB = DBEngine.Workspaces(0).OpenDatabase(MyMdb)

      ' See if an error occurred.
      If Err Then
         MsgBox "Could not find database to open: " & DbName
         IsTableQuery = False
         Exit Function
      End If
   End If

   ' See if the name is in the Tables collection.
   Test = DB.TableDefs(TName).Name
   If Err <> NAME_NOT_IN_COLLECTION Then Found = True

   ' Reset the error variable.
   Err = 0

   ' See if the name is in the Queries collection.
   Test = DB.QueryDefs(TName$).Name
   If Err <> NAME_NOT_IN_COLLECTION Then Found = True

   DB.Close

   IsTableQuery = Found

End Function


CodeMaster::cool:
 

Users who are viewing this thread

Back
Top Bottom