Determining whether an object exists in an mdb

  • Thread starter Thread starter Jim Pockmire
  • Start date Start date
Jim said:
What's the easiest way to do this, especially for a table?

Easiest... dunno

A97, air code

function TableExists(cName as string)as boolean
on error resume next
dim td as tabledef
set tb=currentdb.tabledefs(cName)
tableexists = err<>0
end function
 
Try to open the TableDef for the table in question. If you get an error,
the table doesn't exist.
 
Jim said:
What's the easiest way to do this, especially for a table?

Private Function tableExist(sName As String) As Boolean
Dim tdf As DAO.TableDef

tableExist = False

For Each tdf In CurrentDb.TableDefs
If tdf.Name = sName Then
tableExist = True
End If
Next tdf

End Function

Make sure you have a reference to the DAO object model.
'---------------
' John Mishefske
'---------------
 
Back
Top