Home

Getting a Reference to a Table

 

Description

In most cases, before performing an operation on a table, you will need to indicate what table you are referring to. To get a reference to an existing table in DAO, declare a variable of type DAO.TableDef. Then, assign the TableDefs property of the current database to the variable. TableDefs is a collection of the tables of the current database. To specify what table you are referring to, you can pass its name, as a string to the TableDefs indexed property. Here is an example:

Private Sub cmdContrators_Click()
    Dim curDatabase As DAO.Database
    Dim tblEmployees As DAO.TableDef

    ' Get a reference to the current database
    Set curDatabase = CurrentDb
    ' Get a reference to a table named Employees
    Set tblEmployees = curDatabase.TableDefs(0)

    . . . Use the table as you see fit

    Set tblEmployees = Nothing
End Sub

Home Copyright © 2005-2011 FunctionX, Inc