Running SQL inside forms

  • Thread starter Thread starter Steven Scaife
  • Start date Start date
S

Steven Scaife

How do you create a recordset inside a form

I have

dim rs as recordset

strSQL = "SELECT Time_Of_Appointment FROM Appointment WHERE Agent_ID = " &
Agent_ID.Value

Set rs = DoCmd.RunSQL(strSQL)

but it errors saying expected function or variable.

I am used to doing this in ASP but cant figure out why in access.

any help would be much appreciated
 
Hey Steve,

Use the DAO object library to do this

In the VBA window, select Tools - Refrences and tick Microsoft DAO Object
Library from the list if its not already done so...

then do it like this

Dim db as dao.database
dim rs as dao.recordset
dim strSQL as string

set db = currentdb

strSQL = "SELECT Time_Of_Appointment FROM Appointment WHERE Agent_ID = " &
Agent_ID.Value

set rs = db.openrecordset(strSQL)

you can now use the recordset..

example:

while not rs.eof
debug.print rs("Time_Of_Appointment").value
rs.movenext
wend

Dave
 
Back
Top