Concatenation to variable names. Any Ideas?

  • Thread starter davec via AccessMonster.com
  • Start date
D

davec via AccessMonster.com

I have 77 different fields that are named mth2 - mth78. I want to try and use
a incremental value from a for x = 2 to 78 and try and do something like
below, but my code does not work and I know that. Any ways around it except
for using a select case with a case for each instance. I am trying to
simplify code.

For X = 2 To 78
If rst1!Mth & X = rst2!Mth & X Then
Else
rstCompare!Mth = rst2!Mth & X - rst1!Mth & X
WriteOutRecord = True
End If
Next X
 
M

Marshall Barton

davec said:
I have 77 different fields that are named mth2 - mth78. I want to try and use
a incremental value from a for x = 2 to 78 and try and do something like
below, but my code does not work and I know that. Any ways around it except
for using a select case with a case for each instance. I am trying to
simplify code.

For X = 2 To 78
If rst1!Mth & X = rst2!Mth & X Then
Else
rstCompare!Mth = rst2!Mth & X - rst1!Mth & X
WriteOutRecord = True
End If
Next X


The syntax for that kind of reference is:
If rst1("Mth" & X) = rst2("Mth" & X) Then
 
D

davec via AccessMonster.com

Thanks, that was smooth. Why is it that the answer is always right in front
of your face.

Again,
Thanks

Marshall said:
I have 77 different fields that are named mth2 - mth78. I want to try and use
a incremental value from a for x = 2 to 78 and try and do something like
[quoted text clipped - 9 lines]
End If
Next X

The syntax for that kind of reference is:
If rst1("Mth" & X) = rst2("Mth" & X) Then
 

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