B
bobg
running access 2k FE/BE;
First off - before any points this out
Yes - I know that the ordinal position of fields within a table are
irrelevant as I can change the order in my SELECT.
This has become an anal exploration of academic knowledge!
My full goal is to insert a new field in a specific position in a
table. I'm attempting to do this, by "renumbering" the ordinals below
my insertion point, and then inserting the new field into position.
the new field inserts perfectly where I want - but none of the other
fields get their positions reorganized!!
Could some kind soul please point out where I'm going wrong!!??
here's my relevant code:
'***** start code *****
Private Sub sTestChgOrdinal()
Dim dbs As Database, tbldef As TableDef, c As Integer, pos As Integer
Set dbs = DBEngine.Workspaces(0).OpenDatabase("c:\path\to\mydb.mdb")
Set tbldef = dbs.TableDefs("tbl_inv")
pos = 4 ' position where a new field will be inserted after renum'g
the others
For c = tbldef.Fields.Count - 1 To pos - 1 Step -1
b4 = tbldef.Fields(c).Name & " | " & "B4: " &
tbldef.Fields(c).OrdinalPosition
tbldef.Fields(c).OrdinalPosition = c + 1
' Fields.Refresh ???? would this help?? doesn't seem to....
aftr = " ||| Afr: " & tbldef.Fields(c).OrdinalPosition
Debug.Print b4 & aftr, "c= " & c
Next
' (insert new field & set its ord.) - this works....
Set tbldef = Nothing
Set dbs = Nothing
End Sub
'***** end code *****
tia - Bob
First off - before any points this out
Yes - I know that the ordinal position of fields within a table are
irrelevant as I can change the order in my SELECT.
This has become an anal exploration of academic knowledge!
My full goal is to insert a new field in a specific position in a
table. I'm attempting to do this, by "renumbering" the ordinals below
my insertion point, and then inserting the new field into position.
the new field inserts perfectly where I want - but none of the other
fields get their positions reorganized!!
Could some kind soul please point out where I'm going wrong!!??
here's my relevant code:
'***** start code *****
Private Sub sTestChgOrdinal()
Dim dbs As Database, tbldef As TableDef, c As Integer, pos As Integer
Set dbs = DBEngine.Workspaces(0).OpenDatabase("c:\path\to\mydb.mdb")
Set tbldef = dbs.TableDefs("tbl_inv")
pos = 4 ' position where a new field will be inserted after renum'g
the others
For c = tbldef.Fields.Count - 1 To pos - 1 Step -1
b4 = tbldef.Fields(c).Name & " | " & "B4: " &
tbldef.Fields(c).OrdinalPosition
tbldef.Fields(c).OrdinalPosition = c + 1
' Fields.Refresh ???? would this help?? doesn't seem to....
aftr = " ||| Afr: " & tbldef.Fields(c).OrdinalPosition
Debug.Print b4 & aftr, "c= " & c
Next
' (insert new field & set its ord.) - this works....
Set tbldef = Nothing
Set dbs = Nothing
End Sub
'***** end code *****
tia - Bob