• For…Each…Next (2000 SR-1)

    Author
    Topic
    #408162

    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!

    Viewing 1 reply thread
    Author
    Replies
    • #859283

      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.

    • #859284

      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.

    Viewing 1 reply thread
    Reply To: For…Each…Next (2000 SR-1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: