Results 1 to 2 of 2
  1. #1
    carl g.
    Guest

    Object presence in DB

    Hi,

    I'm wondering if anyone has a quick way to find out if an objects exists in a '97 DB? I have seen something before that tries to instansiate a table object and then traps the error, but I was looking for something a little bit more universal.

    Thanks,

    Carl

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Object presence in DB

    The routine you saw probably looked something like this:

    <pre>Function TableExists(strTableName As String) As Boolean
    ' This procedure returns True or False depending
    ' on whether the table named in strTableName exists.
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef

    On Error Resume Next
    Set dbs = CurrentDb
    Set tdf = dbs.TableDefs(strTableName)
    If Err = 3265 Then
    ' Table does not exist.
    TableExists = False
    Else
    ' Table exists.
    TableExists = True
    End If
    Err = 0
    Set tdf = Nothing
    Set dbs = Nothing
    End Function</pre>


    To do something more global in Access 97, you could query the MSysObjects table for the object type you were checking (you have to use the numeric types, though, and watch out for attached tables). Or you could use the name of the container for the object, (i.e., "tables", "forms", "reports", "modules", "Macros", "queries" and modify the above code to something like this:

    <pre>Public Function TestObjExists(ByVal strObjName As String, _
    ByVal strContainerName As String) As Boolean
    'created by Charlotte Foust 3/5/2001
    'attempts to set an object variable
    'to determine if the object exists
    Dim dbs As DAO.Database
    Dim obj As Object

    On Error Resume Next
    Set dbs = CurrentDb
    Set obj = dbs.Containers(strContainerName).Documents(strObjN ame)
    If Err = 3265 Then
    TestObjExists = False
    Else
    TestObjExists = True
    End If
    'cleanup and exit
    Err = 0
    Set obj = Nothing
    Set dbs = Nothing
    End Function</pre>

    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •