Using a For i = x to n statement with controls?

odin1701

Registered User.
Local time
Today, 10:13
Joined
Dec 6, 2006
Messages
526
Here's the deal.

I've got a form with 78 checkboxes - each with a label.

They are named chk1-chk78 and lbl1-lbl78.

I am wanting to do For Loop to change the labels back color if the check box is checked.

So basically

Code:
For i = 1 to 78

If chk[COLOR="Red"]?[/COLOR].Value = "-1" Then

    Do Stuff

Else

    Do Other Stuff

End If

Next i


What goes where the ? mark is in the code?

Now I know you can do a loop with all check box controls on the form - however, there are several checkboxes which I don't want evaluated in this matter. Any ideas?
 
Try

Me("chk" & i).Value
 
That does it, thanks :)
 
Dim x As Integer

For x = 1 To 3


If Me("chk" & x) Then
Me("label" & x).FontBold = True
Else
Me("label" & x).FontBold = False
End If

Next x


???
 
Why did you do the Dim x as Integer BTW?

I've never had to do that with a for loop.
 
By the way, you could also use a loop of all controls/checkboxes, using the tag property to determine which to include in your process. That might be better if you have a non-contiguous range of numbers.
 
If you're not declaring the integer, you must not have Option Explicit at the top of your modules. Most of us think it's a good idea.
 
As another note... :)

I'm not keen on the entire concept - if the user can't see the box as checked what's going to make it jump out because the label is bold-? Just my humble opinion :)
 
As another note... :)

I'm not keen on the entire concept - if the user can't see the box as checked what's going to make it jump out because the label is bold-? Just my humble opinion :)

It's not for the end user - it's for me. They don't have all checkboxes in all places, but I have a combined form.

I'm changing the label back color from white to red if the box is checked. Because I had missed one the other day and I didn't want to miss any others :P

There's so many of them to pour over this is just easier.
 
Cool, if it helps prevent an error it must be good - :)
 
If you're not declaring the integer, you must not have Option Explicit at the top of your modules. Most of us think it's a good idea.

Think ?? :eek:

THINK ?? :mad:

You must be kidding!! You KNOW it is a good idea and a MUST HAVE for all 'serious' development IMHO.
 
but to go back to the point about the dim

do you NOT have option explicit?- it SO dangerous if you dont

in a code window (not the dbs window) its

TOOLS/OPTIONS/CODE - require variable declarations
 
You must be kidding!! You KNOW it is a good idea and a MUST HAVE for all 'serious' development IMHO.

Well, I agree but I like to guide people towards good habits, not hit them over the head with a sledge hammer. :p

Luckily I have auto-deposit too. :D
 
Well, I agree but I like to guide people towards good habits, not hit them over the head with a sledge hammer. :p

Guiding is a little stronger I think that what you put LOL

but doesnt matter, I know I can be a little headstrong sometimes about some stuff... but it is allmost painfull what some people call "profesional" stuff...

Luckily I have auto-deposit too.
I happen to work at banks quite regularly. If its a big international bank... odds are I can touch it :)

So you had better check your bankstatements ;)
 
but to go back to the point about the dim

do you NOT have option explicit?- it SO dangerous if you dont

in a code window (not the dbs window) its

TOOLS/OPTIONS/CODE - require variable declarations

No I'm not using it. Not really a big deal. The project I'm working on is not very large at all.
 

Users who are viewing this thread

Back
Top Bottom