你如何执行对通过VBA的MS Access 2003中的动态SQL查询? [英] How do you execute a dynamic SQL Query against MS Access 2003 via VBA?

查看:124
本文介绍了你如何执行对通过VBA的MS Access 2003中的动态SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个的超级基本的问题,但我想执行一个查询,我通过对形式驻留在MS Access数据库的某种形式的数值要建。我不认为我需要通过ADO正式,但也许我做的。

This is a super basic question but I'm trying to execute a Query that I'm building via some form values against the MS Access database the form resides in. I don't think I need to go through ADO formally, but maybe I do.

无论如何,一些帮助将AP preciated。对不起,作为一个的n00b。 ;)

Anyway, some help would be appreciated. Sorry for being a n00b. ;)

推荐答案

您可以使用下面的DAO code来查询Access数据库:

You can use the following DAO code to query an Access DB:

Dim rs As DAO.Recordset
Dim db As Database

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Attendance WHERE ClassID = " & ClassID)

do while not rs.EOF
  'do stuff
  rs.movenext
loop

rs.Close
Set rs = Nothing

在我的情况下,是的ClassID窗体上的一个文本框。

In my case, ClassID is a textbox on the form.

这篇关于你如何执行对通过VBA的MS Access 2003中的动态SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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