Looping Variable names

R

RickR

I have a series of 14 checkboxes that I need to
enable/disable after two boxes have been checked. I've
named the boxes chkBox1,chkBox2, etc.

I want to write a quick for-loop like:
==============
for c=1 to 14
if(me.chkBox&c.value=0) then
me.chkBox&c.disable=FALSE
end if
next
==============
but I can't figure out how to get the name reference
(me.chkBox&c) to work properly. Can you help?

Alternately, if there is a better design to get this
functionality, I'd appreciate your input there too.

Thanks - Rick
 
D

Dirk Goldgar

RickR said:
I have a series of 14 checkboxes that I need to
enable/disable after two boxes have been checked. I've
named the boxes chkBox1,chkBox2, etc.

I want to write a quick for-loop like:
==============
for c=1 to 14
if(me.chkBox&c.value=0) then
me.chkBox&c.disable=FALSE
end if
next
==============
but I can't figure out how to get the name reference
(me.chkBox&c) to work properly. Can you help?

Alternately, if there is a better design to get this
functionality, I'd appreciate your input there too.

The pseudo-code you've written can be implemented like this:

For c = 1 To 14
With Me.Controls("chkBox" & c)
If .Value = 0 Then
.Enabled = True
End If
End With
Next

That doesn't quite match your description of what you want to do,
though. Whether it's right or wrong, it shows the technique you're
after.
 
R

Rick

Thanks Dirk, that is exactly the code I was looking for.
I agree, the pseudocode won't do what I want, but it
communicated my need. I can finish the code now. Thanks
for the REALLY quick reply!

Rick
 

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