Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Each Problem

Status
Not open for further replies.

coolscan3

Programmer
Oct 23, 2001
40
0
0
GB
Cannot see a problem with this Code


Dim db As Database
Dim tdf As TableDef
Dim fld As Field
Dim n As Integer

Set db = CurrentDb

DoCmd.SetWarnings False

DoCmd.OpenQuery ("qBelowStandard") **** Make Table Query

Set tdf = db.TableDefs("tBelowStandard")

MsgBox (tdf.Fields.Count) ******* Displays 72

For Each fld In tdf.Fields

n = n + 1

'If Right(fld.Name, 4) <> "Con" Then *** commented ot for test purposes

MsgBox (fld.OrdinalPosition)
tdf.Fields.Delete fld.Name

'End If

Next fld


MsgBox (tdf.Fields.Count) ******* Displays 36

MsgBox (n) ********* Displays 36


The OrdinalPosition is incrementing in twos
 
For i = tdf.Fields.Count - 1 To 0 Step -1
n = n + 1
MsgBox (tdf.Fields(i).OrdinalPosition)
tdf.Fields.Delete tdf.Fields(i).Name
Next i

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I've always found it better to delete backwards when doing this kind of operation, something like:
Code:
For i = tdf.Fields.Count - 1 To 0 Step -1

    MsgBox (tdf.Fields(i).OrdinalPosition)
    tdf.Fields.Delete tdf.Fields(i).Name

Next i
Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Pays to refresh the thread before posting, sorry PHV [blush]

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Thanks for you help, yes this does work fine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top