0

这是我第一次使用 Access,所以我现在有点困惑。这是我的代码,我不知道哪一部分是错误的。没有错误,但单击按钮后没有任何事情发生。谢谢!这是代码:

Private Sub Command12_Click()

Dim db As Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Amity")
Set rs2 = db.OpenRecordset("Opportunity")
With rs2
.AddNew
.Fields("Donor_Code") = rs!Donor_Code
.Update
.Close
End With
rs.Close

End Sub
4

1 回答 1

0

您可以尝试使用 Do 循环:

Private Sub Command12_Click()

  Dim db As Database
  Dim rs As DAO.Recordset
  Dim rs2 As DAO.Recordset

  Set db = CurrentDb()    
  Set rs = db.OpenRecordset("Amity")
  Set rs2 = db.OpenRecordset("Opportunity")

  Do While (Not rs.EOF)
    rs2.AddNew
    rs2.Fields("Donor_Code").Value = rs!Donor_Code.Value
    rs2.Update
    rs.MoveNext
  Loop
'
  rs2.Close
  Set rs2 = Nothing
  rs.Close
  Set rs = Nothing
  Set db = Nothing
'
End Sub
于 2013-11-08T08:29:26.153 回答