You can use VBA to modify the DAO.TableDef
, and specify the new field's OrdinalPosition
property before you append it. See whether you can build on this example session from the Immediate window:
set db = currentdb
for each f in db.tabledefs("DiscardMe").fields : _
? f.name, f.ordinalposition : _
next
ID 0
empid 1
dtpunched 2
fake_yesno 3
set newfield = db.tabledefs("DiscardMe").createfield("fld2", dbtext)
newfield.ordinalposition = 1
db.tabledefs("DiscardMe").fields.append newfield
Note however that table now includes 2 fields with OrdinalPosition
= 1.
for each f in db.tabledefs("DiscardMe").fields : _
? f.name, f.ordinalposition : _
next
ID 0
empid 1
dtpunched 2
fake_yesno 3
fld2 1
The Access help topic explains "Two or more Field objects in the same collection can have the same OrdinalPosition property value, in which case they will be ordered alphabetically." So the query, SELECT TOP 1 DiscardMe.* FROM DiscardMe;
, gives me this:
ID empid fld2 dtpunched fake_yesno
1 100 4/3/2012 0
With some refinement that approach may get you what you want. However, I avoid depending on column's ordinal positions. If they should ever change, I don't want my code to break.