我有记录集rc1
从txt文件中读取值。字段为rtn
,amt
,name
。现在,我从表t_rec
获取数据并将其分配给另一个记录集rc2
。并与记录集rc1
进行比较。
If rd1.Fields![AccountNbr] = rc2.Fields![RTProvided] Then
Set rc2.Fields![ClaimStatus] = "c"
rc2.Fields![DateClosed] = CqDate
rc2.Fields![Audit_LastUpdated] = CqDate
rc2.Fields![Audit_UserAdded] = "System"
如果我编译该程序,我得到的错误就像在vb6中无效使用属性一样。你能帮帮我吗?
Sub DneFroceClose()
CqDate = Format(Date, "dd/MM/yyyy")
Set rcdreclamation = New ADODB.Recordset
With rcdreclamation
.ActiveConnection = objConn
.Source = "SELECT * FROM T_DATA_reclamation"
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open
End With
frmDNELoad.lblStatus.Caption = "Adding record " & lngRecCount & " of " & rcdreclamation.RecordCount & " to database."
frmDNELoad.Refresh
rcdDNE.Open
rcdreclamation.Open
rcdDNE.MoveFirst
rcdreclamation.MoveFirst
Do Until rcdDNE.EOF
Do Until rcdreclamation.EOF
If rcdDNE.Fields![AccountNbr] = rcdreclamation.Fields![RTProvided] Then
Set rcdreclamation.Fields![ClaimStatus] = "c"
rcdreclamation.Fields![DateClosed] = CqDate
rcdreclamation.Fields![Audit_LastUpdated] = CqDate
rcdreclamation.Fields![Audit_UserAdded] = "System"
Exit Do
Else
rcdreclamation.MoveNext
End If
Loop
rcdDNE.MoveNext
rcdreclamation.MoveFirst
Loop
End Sub
答案 0 :(得分:4)
查看上面的代码,我发现这行代码存在问题
Set rc2.Fields![ClaimStatus] = "c"
此处您不需要Set
应该是rc2.Fields![ClaimStatus] = "c"
(如果这是有问题的一行)。
Set rcdreclamation.Fields![ClaimStatus] = "c"
rcdreclamation.Fields![ClaimStatus] = "c"
EDIT2:当您指定对象变量,对象实例或Set
时,需要Nothing
。
EDIT3:另外,你可以写
对于每一行,rcdreclamation![ClaimStatus]
代替rcdreclamation.Fields![ClaimStatus]
(免责声明:我希望我的VB6语法正确。已经有一段时间了。)