Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if a table exists (Access 2000)

    If a table exists in destinaztion database

    I want to send a table to a destination database only if a table called students1 does not exist.
    Is there any way to find out whether a table under such a name exists in the destination database?
    My comand is the following
    DoCmd.TransferDatabase acExport, "Microsoft Access", appath, acTable, "students", "students1"

    A table under the name students should already exist in the database.I want to send to this database another table called students1
    but only if students 1 is not already there.
    Can somebody help me?

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if a table exists (Access 2000)

    Enter this function in a module.
    Add a reference to Microsoft DAO 3.6 Object Library in Tools | References if it isn't already add.
    Save the module with a name anything else but tblExist.

    <pre>Function tblExist(dbName As String, tblName As String) As Boolean
    Dim wks As DAO.Workspace
    Dim db As DAO.Database
    Dim tdf As TableDef
    Set wks = CreateWorkspace("", "admin", "", dbUseJet)
    Set db = wks.OpenDatabase(dbName)
    For Each tdf In db.TableDefs
    If tdf.Name = tblName Then
    tblExist = True
    GoTo EXIT_tblExist
    End If
    Next
    tblExist = False
    EXIT_tblExist:
    Set db = Nothing
    Set wks = Nothing
    End Function</pre>

    If you want, you can add some code to check the existence of the database.
    Now you can use <pre>IF tblExist(appath,"students1") = False Then
    DoCmd.TransferDatabase acExport, "Microsoft Access", appath, _
    acTable, "students", "students1"
    Else
    'code to do somthing else
    End If
    </pre>

    Francois

Posting Permissions

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