vb6中的属性使用无效

时间:2009-12-07 17:58:23

标签: vb6

我有记录集rc1从txt文件中读取值。字段为rtnamtname。现在,我从表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

1 个答案:

答案 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语法正确。已经有一段时间了。)