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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Item not found in this collection

Status
Not open for further replies.

gdev

Technical User
Joined
Mar 12, 2001
Messages
38
Hi,

I have 3 fields in a table; when the item gets to the second field,
I get this error message: item not found in this collection.

Here's the code I am using:

Dim x As Integer
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strField As String

Set db = CurrentDb


Set tdf = db.TableDefs("tTest")


For x = 0 To tdf.Fields.Count - 1

Set fld = tdf.Fields(x)
strField = fld.Name
Debug.Print strField
Debug.Print x
If strField <> "1stField" Then

tdf.Fields.Delete (strField)
Debug.Print strField
End If

Next
Set db = Nothing
Set tdf = Nothing


Please tell me what I'm doing wrong.

Thanks
Gwen
 
Replace this:
For x = 0 To tdf.Fields.Count - 1
By this:
For x = tdf.Fields.Count - 1 To 0 Step -1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks

Works like a charm!


Gwen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top