循环记录集vb6

时间:2018-05-26 07:37:31

标签: vb6 access

所以,我已经做了一百万种不同的方式,但这让我感到困扰。我试图遍历记录集,识别一个数字并与下一条记录进行比较。如果匹配,我想更改匹配值。它似乎在某种程度上有效,但随后我得到所有记录为"匹配" ....说有没有匹配的记录'。我确定这是一件让我感到愚蠢的事情,所以如果有人能在这里指出我的缺陷,那就太棒了!一如既往,提前谢谢!!!

    con.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\Books.mdb;" & _
"Jet OLEDB:Engine Type=4;"

rs1.Open "A", con, adOpenKeyset, adLockPessimistic, adCmdTableDirect
rs2.Open "B", con, adOpenKeyset, adLockPessimistic, adCmdTableDirect

rs1.MoveFirst
While Not rs1.EOF
    rs2.MoveFirst
    While Not rs2.EOF
         If rs1("ID").Value = rs2("ID").Value Then
         With rs2
            !Matching_Criteria = "Matched"
            .Update
            End With
         Else
             With rs2
            !Matching_Criteria = "UnMatched"
            .Update
            End With
         End If
        rs2.MoveNext
    Wend
rs1.MoveNext
Wend

1 个答案:

答案 0 :(得分:-2)

  1. 确保桌子的机器人为您提供垄断访问和/或使用静态rst(我不记得清楚)

  2. 填充rst's:

    .MoveLast
    .MoveFirst
    lCnt = .RecordsCount'(引擎不要格式化它......)

  3. 使用For i = 1 to lCnt代替While ... Wend