Variable addressing of fields

V

vtj

I have a table that has fields named 'item1', 'item2'...
I want to combine them together but the rst1![cntr] returns an error that
the item is not in the collection. i know that the recordset has a field
named item1 and that there is a value contained in the field of the record
being addressed.

For counter = 1 To 20
cntr = "item" & counter
rst1!item21 = (rst1!item21 & rst1![cntr])
Next

How can I address the 'rst1![cntr]' at the end of line 3 above to retrieve
the value contained in the table?

Thanks for your help!!
 
V

vtj

I still get the error message now saying that rst1.Fields(cntr) is 'item not
found in this collection' .

John Spencer said:
Try the following

rst1!item21 = rst1!item21 & rst1.Fields(cntr)

vtj said:
I have a table that has fields named 'item1', 'item2'...
I want to combine them together but the rst1![cntr] returns an error that
the item is not in the collection. i know that the recordset has a field
named item1 and that there is a value contained in the field of the record
being addressed.

For counter = 1 To 20
cntr = "item" & counter
rst1!item21 = (rst1!item21 & rst1![cntr])
Next

How can I address the 'rst1![cntr]' at the end of line 3 above to retrieve
the value contained in the table?

Thanks for your help!!
 
V

vtj

I needed to add an edit/update to the code. then it works!! THANKS!

John Spencer said:
Try the following

rst1!item21 = rst1!item21 & rst1.Fields(cntr)

vtj said:
I have a table that has fields named 'item1', 'item2'...
I want to combine them together but the rst1![cntr] returns an error that
the item is not in the collection. i know that the recordset has a field
named item1 and that there is a value contained in the field of the record
being addressed.

For counter = 1 To 20
cntr = "item" & counter
rst1!item21 = (rst1!item21 & rst1![cntr])
Next

How can I address the 'rst1![cntr]' at the end of line 3 above to retrieve
the value contained in the table?

Thanks for your help!!
 
J

John Spencer

Well, if the field exists in the recordset you should be able to reference
it using any of these methods

rst1!item20
rst1("Item20")
rst1.Fields("Item20")

Do you have fields in the recordset named Item1 to Item20?
Is the fieldname Item1, Item01, or Item 1?

Normally, when I have this type of problem, I've failed to include the field
in the recordset or misspelled the name of the field.

Beyond that I have no suggestions.
vtj said:
I still get the error message now saying that rst1.Fields(cntr) is 'item
not
found in this collection' .

John Spencer said:
Try the following

rst1!item21 = rst1!item21 & rst1.Fields(cntr)

vtj said:
I have a table that has fields named 'item1', 'item2'...
I want to combine them together but the rst1![cntr] returns an error
that
the item is not in the collection. i know that the recordset has a
field
named item1 and that there is a value contained in the field of the
record
being addressed.

For counter = 1 To 20
cntr = "item" & counter
rst1!item21 = (rst1!item21 & rst1![cntr])
Next

How can I address the 'rst1![cntr]' at the end of line 3 above to
retrieve
the value contained in the table?

Thanks for your help!!
 

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