[AccessD] Question about the TableDef.Fields collection
Jim Dettman
jimdettman at verizon.net
Fri Aug 26 10:56:00 CDT 2022
Arthur,
<< But in tables containing no AutoNumber field, is there a Field attribute
that identifies the PK of the table of interest?>>
The only attribute to indicate that a field is the "PrimaryKey" in Access
is that it is a field in the index for the table which has the PrimaryKey
property set to True. The index is also name "PrimaryKey"
? CurrentDB().TableDefs("Table1").Indexes(0).Name
PrimaryKey
? CurrentDB().TableDefs("Table1").Indexes(0).Primary
True
? CurrentDB().TableDefs("Table1").Indexes(0).Fields(0).Name
ID1
Jim.
-----Original Message-----
From: AccessD On Behalf Of Arthur Fuller
Sent: Friday, August 26, 2022 9:46 AM
To: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>
Subject: [AccessD] Question about the TableDef.Fields collection
Like most Access programmers, I use AutoNumber fields as Primary Keys
whenever it makes sense. However, it doesn't always make sense, and this is
particularly so when the table of interest contains a relatively small
number of rows. The reason I say this is because using an AutoNumber as the
PK demands additional logic, to prevent otherwise equal rows from being
added. For example, in a table of Countries, using an AutoNumber as the PK
does not prevent the addition of country names that would duplicate an
existing row. You could add Israel a dozen times, with each row having an
AutoNumber. That said, I can think of no reason to have an AutoNumber in a
table unless it is the PK.
But in tables containing no AutoNumber field, is there a Field attribute
that identifies the PK of the table of interest?
Thanks in advance.
--
Arthur
--
AccessD mailing list
AccessD at databaseadvisors.com
https://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
More information about the AccessD
mailing list