check box state in visual basic

G

Guest

I have a form with check boxes. When I set the check box with codeit works:
Do
If Controls(Ctrl).ControlType = acCheckBox Then
LeftTag = Left(Controls(Ctrl).Tag, 2)
If LeftTag = FFofs Then
Controls(Ctrl).Value = Checked
End If
End If
Ctrl = Ctrl + 1
Loop Until (Ctrl >= MaxCtrl)

When I click on them manually, other code does not detect that the check box
is "checked"
Do
If Controls(Ctrl).ControlType = acCheckBox Then 'this control IS a
check box
If (Controls(Ctrl).Value = Checked) Then 'check box IS checked
WorkTag = Controls(Ctrl).Tag
FFofs = Val(Left(WorkTag, 2))
Qual = Val(Right(WorkTag, 2))
MsgBox ("Name " + FFname(FFofs) + " Qualification -> " + Str(Qual))
End If
End If 'controls...
Ctrl = Ctrl + 1
Loop Until (Ctrl >= MaxCtrl)

Sorry this is so long but I wanted it as clear as possible
 
G

Guest

What is Checked? If it is not either a constant or a variable with the value
True (-1), Then is has no meaning. Change Checked to True.
 
G

Guest

Basically I click on the check box and a "check mark" appears. The code
looking at the state of the checkbox says it is NOT checked. I'm using the
built in Controls() array of the form to check the status e.g.
controls(x).Value=Checked.
 
J

J_Goddard via AccessMonster.com

Kruppy -

A very good example of why you should use Option Explicit in all your code
modules - your code would not have compiled, and marked Checked as an
undeclared variable.

In your code as you have it, "Checked" is assumed by VB to have a value of 0,
which is interpreted as "False". A checkbox is just a visual representation
of boolean (Yes/No) data, which has only the values True or False; the idea
of it having a "Checked" property is just for us humans.

John

Should be:
controls(x).Value=True

Checked means nothing.
Basically I click on the check box and a "check mark" appears. The code
looking at the state of the checkbox says it is NOT checked. I'm using the
[quoted text clipped - 31 lines]
 
G

Guest

J_Goddard,
Thanks for the help. I'm used to Pascal which will NEVER let me use a
variable without declaring it first.
I Added the line "Option Explicit" to the module before I removed
"Checked" thinking that it would kick that out and all other variables that I
had accidentally used. It didn't. The line is at the first top of the module
but not the first line of the module


J_Goddard via AccessMonster.com said:
Kruppy -

A very good example of why you should use Option Explicit in all your code
modules - your code would not have compiled, and marked Checked as an
undeclared variable.

In your code as you have it, "Checked" is assumed by VB to have a value of 0,
which is interpreted as "False". A checkbox is just a visual representation
of boolean (Yes/No) data, which has only the values True or False; the idea
of it having a "Checked" property is just for us humans.

John

Should be:
controls(x).Value=True

Checked means nothing.
Basically I click on the check box and a "check mark" appears. The code
looking at the state of the checkbox says it is NOT checked. I'm using the
[quoted text clipped - 31 lines]
Sorry this is so long but I wanted it as clear as possible
 
J

J_Goddard via AccessMonster.com

Hi -

It turns out that "Checked" is a valid property of some objects! I looked
into the help (Access 2000) and found it as a property for BalloonCheckbox
objects. I then did exactly as you did; I put a bit of code in a test form
that said If text0 = Checked then...., and it compiled just fine (even with
Option Explicit) - it didn't give a runtime error either.

Live and learn!

John


J_Goddard,
Thanks for the help. I'm used to Pascal which will NEVER let me use a
variable without declaring it first.
I Added the line "Option Explicit" to the module before I removed
"Checked" thinking that it would kick that out and all other variables that I
had accidentally used. It didn't. The line is at the first top of the module
but not the first line of the module
[quoted text clipped - 18 lines]
 

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