[AccessD] 2 Questions concerning lists of fields and indexes

Heenan, Lambert Lambert.Heenan at chartisinsurance.com
Wed Oct 17 08:25:02 CDT 2012


Air Code...

Dim fld as DAO.Field
Dim Td As DAO.TableDef 

' iterating the fields

Set Td = CurrentDb.TableDefs(strYourTableName)

For Each fld in Td.Fields
	Debug.Print fld.Name
Next fld

' Code from an old App...
' Indexes
Dim cntKey  as Integer
Dim curIdxFld As Field
Dim cntIdx As Integer
Dim curFld As Field

For cntKey = 0 To Td.Indexes.Count - 1
    Set curIdx = Td.Indexes(cntKey)
    '** Loop though all the fields in the current index
    For cntIdx = 0 To curIdx.Fields.Count - 1
        Set curIdxFld = curIdx.Fields(cntIdx)
        '* is the current field part of the primary key?
        If (curFld.Name = curIdxFld.Name) And (curIdx.Primary = True) Then
            ' log your primary key setting here
        End If
    Next cntIdx ' move to next field in the current index
Next cntKey ' move to next index in current table

Lambert

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller
Sent: Wednesday, October 17, 2012 9:14 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] 2 Questions concerning lists of fields and indexes

I'm having a senior moment. I can't remember how, given a table name, to:

1. Iterate through its field list
2. identify the field(s) involved in its PK

TIA,
Arthur
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list