Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Aug 2001
    Location
    Richmond, Virginia, USA
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    For...Each...Next (2000 SR-1)

    Hi,

    Does anyone know if there a way to search a collection backwards using the for...next...each. What I'd like to do is cycle through the tabledefs in db.tabledefs backwards. Here's the code that currently is cycling through the records:

    Dim db As Database
    Dim tdf As TableDef

    Set db = CurrentDb()

    For Each tdf In db.TableDefs

    If Left$(tdf.Name, 4) = "MSys" Then
    ' Don't restore system files
    ElseIf _
    tdf.Name = "tblVersion" Or _
    tdf.Name = "tblDigiOutput" Or _
    tdf.Name = "tblGLTonnage" Or _
    tdf.Name = "tblMeatInventoryWorksheet" Or _
    tdf.Name = "tblRetailCutsInventoryWorksheet" Then
    ' Don't restore temporary files or version file
    Else
    Me.lblStatusMessage.Caption = "Restoring " & _
    tdf.Name
    Me.Repaint
    DoCmd.TransferText TransferType:=acImportDelim, _
    SpecificationName:=tdf.Name & _
    " Import Specification", _
    TableName:=tdf.Name, _
    FileName:=strPath & _
    tdf.Name & _
    ".txt", _
    HasFieldNames:=True
    End If
    Next tdf

    Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: For...Each...Next (2000 SR-1)

    Use something like this:

    Dim i As Long
    For i = db.TableDefs.Count - 1 To 0 Step -1
    Set tdf = db.TableDefs(i)
    ...
    Next i

    Note that the index number for the TableDefs collection is zero-based.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •