How to address data fields through generated names

G

Guest

Normally I would adress fields in a recordset by their name - like:

Set rst = dbs.OpenRecordset(sql)
With rst
.AddNew
!FN1 = val1
.Update
End With

Now I have a table with the fields FN1, FN2, FN3,... FN25

Is there a way to adress these fields with a counter - i.e. build up the
name from the string "FN" & i where i is the counter?

I would then have a loop:

for i = 1 to max
!("FN" & i) = val(i)
next i

This doesn't wotk - but I believe there is a way to do it - possibly using
the .fields! syntax - but I have just not managed to do it.
 
D

Douglas J Steele

Try

For i = 1 to max
.Fields("FN" & i) = val(i)
Next i

If that doesn't work, report back what error you get.
 
D

Douglas J Steele

Wouldn't that always update the same field?

(I assume you mean !(i) = val(i+1))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top