Recordset: retrieve values from recordset using variable for field

A

Anna S

Hi
Does anyone know how to use a variable field name to retrieve values from a
recordset
eg
str1 = rst1!FieldName
returns the value in the FieldName field of rst1 as desired but I need to be
able to use the same statement to access values in other fields as well.

strFieldName = "FieldName"
str1 = rst1!strFieldName
What is the correct syntax to use on the second line above if I want str1 to
hold the value in the FieldName field?

Any help would be greatly appreciated.
thanks
Anna
 
D

Dirk Goldgar

Anna S said:
Hi
Does anyone know how to use a variable field name to retrieve values
from a recordset
eg
str1 = rst1!FieldName
returns the value in the FieldName field of rst1 as desired but I
need to be able to use the same statement to access values in other
fields as well.

strFieldName = "FieldName"
str1 = rst1!strFieldName
What is the correct syntax to use on the second line above if I want
str1 to hold the value in the FieldName field?

Any help would be greatly appreciated.
thanks
Anna

I think what you're after is

strFieldName = "FieldName"
str1 = rst1(strFieldName)
 

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