Access 2010 VBA 查询表并遍历结果 [英] Access 2010 VBA query a table and iterate through results

查看:71
本文介绍了Access 2010 VBA 查询表并遍历结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要对表执行的查询.有了结果,我想做点什么.在我的脑海中,伪代码是:

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 where some condition";
var results = db.getResults(q);
foreach (row r in results )
    do something with result

我如何与 vba 如此相似?

How would I so something similar with vba?

推荐答案

DAO 是 Access 原生的,迄今为止最适合一般用途.ADO 有它的位置,但不太可能就是这样.

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

这篇关于Access 2010 VBA 查询表并遍历结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆