访问记录集不更新表

时间:2021-04-22 11:41:22

标签: vba ms-access-2013 recordset

我正在学习如何处理 Access VBA 记录集。

在下面的示例中,我使用 SQL 查询打开我的记录集并使用 strName 列对数据进行排序。当我调试代码时,我可以看到查询正在运行,但是我不知道为什么表没有使用已排序的行进行更新。有什么建议吗?

enter image description here

Option Compare Database
Option Explicit

Sub OrderDB()

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

    'Set the DAO database to current Access db
     Set db = CurrentDb

    'Open the table as the recordset
     Set rs = db.OpenRecordset("SELECT * FROM Table1 order by strName", dbOpenDynaset)
     
    'Process the rows
    Do
    
      Debug.Print rs!strName
      rs.Edit
      rs.Update
      rs.MoveNext
      
    Loop Until rs.EOF
      
    'Cleanup
    rs.Close
    Set rs = Nothing
   
End Sub

0 个答案:

没有答案
相关问题