你如何执行对通过VBA的MS Access 2003中的动态SQL查询?动态、MS、VBA、Access

2023-09-08 11:15:25 作者:硬汉

这是一个的超级基本的问题,但我想执行一个查询,我通过对形式驻留在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.