Results 1 to 7 of 7

Thread: Test for table

  1. #1
    Join Date
    Jan 2004
    Posts
    77

    Unanswered: Test for table

    Is there a way to code a test for a specific tablename (i.e., if table exists, run macro otherwise exit)?

    Here's some code I have that tests for a file:

    If Dir("c:\sidewalks\swk_inspect.mdb") = "" Then
    Else
    DoCmd.RunMacro ("macImport")
    EndIf

    However, now I want to test for a specific tablename.

    Thanks,
    SKK

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    A very brief search turned up a number of threads, including this one with several different methods:

    http://www.dbforums.com/t1005591.html
    Paul

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Try this function
    PHP Code:
    Function IsTableExist(TableName As String) As Boolean
      
      Dim db 
    As Databasetbl As TableDef

      On Error 
    GoTo ERR_Table_Exist
        Set db 
    CurrentDb  :  Set tbl db.TableDefs(TableName)
        
    IsTableExist True
        
    EXIT_Table_Exist
    :
      
    Set db NothingSet tbl Nothing
      
    Exit Function

    ERR_Table_Exist:
        
    IsTableExist False
        Resume EXIT_Table_Exist
    End 
    Function 
    Example to call it

    if IsTableExist("yourTableNameUwant2Check") then
    DoCmd.RunSQL ("DROP TABLE yourTableNameUwant2Check")
    End IF

  4. #4
    Join Date
    Jan 2004
    Posts
    77
    Excellent,

    Thanks Paul,
    SKK

  5. #5
    Join Date
    Jan 2004
    Posts
    77
    Paul,

    One more thing. I want to test the location of a table in a remote network database. Where in the code found in http://www.mvps.org/access/tables/tbl0001.htm do I place the path, database name, and table name?

    Thanks,
    SKK

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    just pass the name of the table you are looking for as part of the function call

    fExistTable(<mytablename>)

    you will need to make sure the DAO library is selected as part of your code

    view a form in design
    switch to code window
    tools | references
    select microsoft DAO 3.6 or later

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by esskaykay
    I want to test the location of a table in a remote network database.
    Example to code to instantiate a database object referencing a remote database:
    Code:
     Set db = Workspaces(0).OpenDatabase("C:\MyDatabaseFolder\MyDB.mdb")
    You could alter your function to accept the database fully qualified name as a parameter

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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