CurrentDb Method Example

The following example uses the CurrentDb method to return a Database object variable pointing to the current database. It then enumerates all the fields in the Employees table in that database.

Sub ListFields()
    Dim dbs As Database, tdf As TableDef, fld As Field

    ' Return Database object variable pointing to current database.
    Set dbs = CurrentDb
    ' Return TableDef object variable pointing to Employees table.
    Set tdf = dbs.TableDefs!Employees
    ' Enumerate fields in Employees table.
    For Each fld In tdf.Fields
        Debug.Print fld.Name
    Next fld
End Sub