Reading Data from tables

  • Thread starter Thread starter Dan Perkins
  • Start date Start date
D

Dan Perkins

I am using MS ACCESS VB to loop through all of the records
in a table.
The problem is that, I can't seem to figure out how to get
the values of the fields from the current record.

I am using DoCMD.GoToRecord to get each record.
 
Try Me.Recordset!columnName

You will have to change the columnName to fit your table.

Hope This Helps
Gerald Stanley MCSD
 
Is there some setup that is required to use that.
I keep getting an Invalid use of the Me keyword.
I looked in the online help under Recordset at it had a
couple of examples that used
Dim Myvar as DAO.Recordset
But I get an error with that because the user defined type
does not exist.
 
I'm guessing that your code is in a module, not a form. In
which case you should use code along the lines of
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("tableName")

Do Until rs.EOF
(your code goes here)

rs.MoveNext
Loop

To refrence each column, use rs!columnName

You need to add in the DAO Object Library to the
References. In the VB Editor, goto Tools-> References and
select the entry for DAO 3.6 (or 3.51) Object Library.

Hope This Helps
Gerald Stanley MCSD
 
Thanks, that works perfectly!

-----Original Message-----
I'm guessing that your code is in a module, not a form. In
which case you should use code along the lines of
Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("tableName")

Do Until rs.EOF
(your code goes here)

rs.MoveNext
Loop

To refrence each column, use rs!columnName

You need to add in the DAO Object Library to the
References. In the VB Editor, goto Tools-> References and
select the entry for DAO 3.6 (or 3.51) Object Library.

Hope This Helps
Gerald Stanley MCSD
.
 
Back
Top