how to reference a field in a table in code

  • Thread starter Thread starter Rover
  • Start date Start date
R

Rover

I have the following code (which doesn't work).

set rstIN = dbs.OpenRecordset("table", dbOpenDyanset)

with rstIN

for x = 1 to 10
if !field(x) = "m" then
etc, etc etc....

I know I can reference the fields in the table like an array but the
above code is NOT it. What needs to replace !field(x)?

I knew how to do this but can't find my example code...
 
Try this
set rstIN = dbs.OpenRecordset("table", dbOpenDyanset)
for x = 1 to 10
If rstIN("Fieldname" & x) = "m" then
etc, etc etc....
 
What I'm really trying to do is got through the first 10 fields of the
table to detrmine if the value = "m" so I don't want to use the field name.
 
Rover,

I believe it can be done with the "Fields" collection:

If !Fields(x) = "m" Then
...

HTH

RuralGuy
 
set rstIN = dbs.OpenRecordset("table", dbOpenDyanset)
With rstIN
For x = 1 to 10
if .Fields(x) = "m" then
etc, etc etc....

The collection name is Fields, not Field, and you should be using a ., not
an !.

Oh, and by the way, the first 10 fields would be 0 to 9.
 
Back
Top