看似无限循环

时间:2015-04-13 13:57:21

标签: excel-vba vbscript vba excel

这个循环应该循环遍历行,当它到达结尾时它应该退出循环。它似乎陷入困境而不是退出。我在一个不同的宏中使用了一个几乎完全相同的循环,为什么这个不能在这里工作呢?

    If not rs2.eof Then
        rs2.movefirst
        Do until rs2.eof

            Set ORDERLINE = ORDERLINES(CInt(rs2("ROW"))-1).VALUE

            If ORDERLINE("udfStringCol8") = trim(group) Then
                For i = 0 to (Lcnt - 1) 
                    Set ORDERLINE = ORDERLINES(i).VALUE
                    objExcel.Cells(i+2, 1).Value = ORDERLINE("PART_ID")
                    objExcel.Cells(i+2, 2).Value = ORDERLINE("DESCRIPTION")
                    objExcel.Cells(i+2, 3).Value = ORDERLINE("USER_3")
                    objExcel.Cells(i+2, 4).Value = ORDERLINE("USER_6") 
                    objExcel.Cells(i+2, 5).Value = ORDERLINE("USER_8")
                    objExcel.Cells(i+2, 6).Value = ORDERLINE("USER_7")
                    rs2.movenext
                Next    
            End If
        loop 
    End If
    rs2.close

1 个答案:

答案 0 :(得分:0)

    Do until rs2.eof
        If ORDERLINE("udfStringCol8") = trim(group) Then ' this doesn't happen
        'some code here
          rs2.movenext ' So this doesn't move next
        End If
    loop