[英]Looping through recordset vb6
So, I've done this a million different ways but this is bothering me a bit.所以,我已经以一百万种不同的方式完成了这件事,但这让我有点困扰。 I'm trying to loop through a recordset, identify a number and compare to the next record.
我正在尝试遍历记录集,识别一个数字并与下一条记录进行比较。 If they match, I want to change matching value.
如果它们匹配,我想更改匹配值。 It seems to work, somewhat, but then I get all records as "Matched".... saying that there is 'No matched record'.
它似乎有效,但后来我将所有记录都设为“匹配”……说“没有匹配的记录”。 I'm sure it's something dumb I'm missing so if anyone could point out my flaw here, that would be awesome!
我确定这是我遗漏的一些愚蠢的东西,所以如果有人能在这里指出我的缺陷,那就太棒了! As always, thanks in advance!!!
与往常一样,提前致谢!!!
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
Be sure that bot of tables are in monopoly access for you and/or use static rst (I don't remember clearly)确保 bot of table 为您垄断访问和/或使用静态 rst(我记不清了)
Populate both of rst's:填充两个 rst:
.MoveLast .MoveLast
.MoveFirst .先行
lCnt = .RecordsCount ' (engine wan't to format it ...) lCnt = .RecordsCount ' (引擎不想格式化它......)
Use For i = 1 to lCnt
instead of While ... Wend
.使用
For i = 1 to lCnt
而不是While ... Wend
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.