using variable to ref. recordset field

  • Thread starter Thread starter John Thomas
  • Start date Start date
J

John Thomas

I am having trouble using a variable in a Recordset, I have, RS as Recordset

Then when I try to use it in the following statement, I want to use a
variable in stead of the field name, but it says it cannot find the field. I
have verified the variable is right, so it must be in the syntax?

Dim var4 as String 'is the variable field name

I've tried the following variations with it but none work:

var1 = RS!var4

var1 = RS![var4]

var1 = RS![" & var4 & "]

Thanks John
 
Thanks, worked great!

Ken Snell said:
Close....

var1 = RS.Fields(var4)


--
Ken Snell
<MS ACCESS MVP>

John Thomas said:
I am having trouble using a variable in a Recordset, I have, RS as Recordset

Then when I try to use it in the following statement, I want to use a
variable in stead of the field name, but it says it cannot find the
field.
I
have verified the variable is right, so it must be in the syntax?

Dim var4 as String 'is the variable field name

I've tried the following variations with it but none work:

var1 = RS!var4

var1 = RS![var4]

var1 = RS![" & var4 & "]

Thanks John
 
Back
Top