Reading Table Records

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

Thank you for reading my question.

I have to create a small interface using MS Access, which
I am not very familiar with, and I am stuck on something
which should be simple. How can I read each record from a
table one by one? I have tried various things like

Dim rsAssignments As Recordset
Set rsAssignments = DoCmd.RunSQL("SELECT * FROM
ActvCodeAssignments ORDER BY task_code;")

With this I get an compile error 'Expected function or
variable' and I cannot find what I need using help menus.
Can I create a recordset or should I be reading records
directly from the table? I do this stuff all the time in
VB6, but Access has me stumped.

Any help would be greatly appreciated.

Kevin B
 
Kevin,

You will need to add a DAO reference to your project (DAO 3.51 for A97, DAO
3.6 for A2K or later) and modify your code as follows:

Dim db as DAO.Database
Dim rsAssignments As DAO.Recordset

Set db = CurrentDb()
Set rsAssignments = db.OpenRecordset("SELECT * FROM ActvCodeAssignments
ORDER BY task_code;")
(watch out for wrapping above)

at the end, don't forget to:
rsAssignments.Close
Set rsAssignments = Nothing
Set db = Nothing

HTH,
Nikos
 
Thank you, works great.
-----Original Message-----
Kevin,

You will need to add a DAO reference to your project (DAO 3.51 for A97, DAO
3.6 for A2K or later) and modify your code as follows:

Dim db as DAO.Database
Dim rsAssignments As DAO.Recordset

Set db = CurrentDb()
Set rsAssignments = db.OpenRecordset("SELECT * FROM ActvCodeAssignments
ORDER BY task_code;")
(watch out for wrapping above)

at the end, don't forget to:
rsAssignments.Close
Set rsAssignments = Nothing
Set db = Nothing

HTH,
Nikos





.
 
Back
Top