use a variable with a me.field name

mdlp
mdlp used Ask the Experts™
on
I have a form with a set of 20 Command Buttons and 20 unbound Text box's.
tbP1, tbP2, tbP3 - 20
cbP1, cbP2, cbP3 - 20
dim counter as integer
dim sCurrValue


while counter <21
  if isnull(me.tbP(counter)) then
     me.cbP(counter).Visible = False
 else
  sCurrValue = me.tbP(counter)
 end if


How do I correctly make me.tbP"Counter" the same as me.tbP1 -20 for each loop.
I know that I can create 20 if then's, but this list grows and shrinks at different site.

I need to replace the Number in the me.name with the current counter value, I hope I am clear with this question.

Thank you Experts
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Try

Dim i As Integer

Dim sCurrValue As String

Do while i<21

  if isnull(me("tbP" & i)) then
     me("cbP" & i).Visible = False
 else
  sCurrValue = me("tbP" & i)

 end if

i=i+1

Loop

Author

Commented:
Exactly what I needed, thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial