Access 2010 VBA query a table and iterate through results

后端 未结 3 610
独厮守ぢ
独厮守ぢ 2020-12-14 09:45

I have a query that I want to execute against a table. With the results I want to do something. In my head the pseudo code is:

var q = \"select * from table          


        
3条回答
  •  伪装坚强ぢ
    2020-12-14 10:38

    DAO is native to Access and by far the best for general use. ADO has its place, but it is unlikely that this is it.

     Dim rs As DAO.Recordset
     Dim db As Database
     Dim strSQL as String
    
     Set db=CurrentDB
    
     strSQL = "select * from table where some condition"
    
     Set rs = db.OpenRecordset(strSQL)
    
     Do While Not rs.EOF
    
        rs.Edit
        rs!SomeField = "Abc"
        rs!OtherField = 2
        rs!ADate = Date()
        rs.Update
    
        rs.MoveNext
    Loop
    

提交回复
热议问题