CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Location
    UK
    Posts
    14

    How do I determine if a table exists in Acess DB

    I would like to determine if a table exists in an Access database from my VB application using DAO. I can delete a table even copy from another database, but I'm having a problem doing this one.

    Help appreciated


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: How do I determine if a table exists in Acess DB

    You can do this on two ways

    The quick and dirty way: you just try to access the table and look if an error has occured

    dim TD as TableDef
    on error resume next
    set TD = DB.TableDefs("MyTable")
    If Err.Number <> 0 then
    'Table does not exist
    else
    ' Table exists
    End If



    or you can do it the nice (but mostly a wee bit slower), just enumerate throug the tables an see if the name matches

    Dim TD as TableDef
    for Each TD in DB.TableDefs
    If TD.Name = "myTable" then
    ' we found it
    End If
    next TD




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Apr 2001
    Location
    UK
    Posts
    14

    Re: How do I determine if a table exists in Acess DB

    Thanks, I'll give it a whirl

    John lamb


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured