Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a dynamic SQL Query against MS Access 2003

Tags:

vba

ms-access

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.

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

like image 434
Tim Visher Avatar asked Feb 24 '26 17:02

Tim Visher


1 Answers

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

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

like image 124
jinsungy Avatar answered Feb 27 '26 01:02

jinsungy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!