The Default value of a check box.

  • Thread starter Thread starter Rani
  • Start date Start date
R

Rani

I am trying to set a condition to display something according to a check box
condition AKA if not checked then item a will not be displayed if checked
item a will be displayed.

what's the correct way for doing it ?
I am currently using an after update event but am producing nothing.
here is the code:

Private Sub CbPurOption_AfterUpdate()
If Me.CbPurOption = 1 Then
Me.BoxPurOpt.Visible = True
Else
Me.BoxPurOpt.Visible = False
End If
End Sub
 
Try

Me.BoxPurOpt.Visible = me.CbPurOption

(Access uses -1 to represent true (but you can just use the value True)
which is why your code fails.)
 
let me understand:
my code defines:
if the option (CbPurOption
) is true (= 1) then show this filed, what you wrote seems to define that
if the option CbPurOption
) is true (= 1) then set the visible property of BoxPurOpt to the checkbox
assuming the checkbox produces one.
well it doesn't work for me but it seems to be a long circular way I think
true should be the shorter preferred route to take as it is working with
option groups.
any other idea ?
 
What Andrew proposed is correct.

Here's the test code that works in A2K:

Private Sub Check13_AfterUpdate()
Me.Combo5.Visible = Me.Check13
End Sub

Note: Visible is a Boolean Property so you can assign the value of the
CheckBox to the Visible Property of the Control.
 
THANKS guys,
so basically is shouldn't use an if statement as in an option group ?
am I correct ?
 
Be careful: CheckBoxes in an OptionGroup are DIFFERENT from stand-alone
CheckBoxes. Stand-alone CheckBox has True, False and Null as possible
values. CheckBoxes in an OptionGroup don't have independent values and you
have to use the value of the OptionGroup (usually 1, 2, 3, ... up to the
number of options you have in the OptionGroup).

Andrew and my answer were based on independent CheckBox since you did not
mention the OptionGroup until now.
 
No that is fine it is a stand alone checkbox just from reading Andrews email
it wasn't so clear that this is the case.
anyhow thanks for your help guys I appreciate it.

Ran
 
Rani said:
No that is fine it is a stand alone checkbox just from reading Andrews email
it wasn't so clear that this is the case.
anyhow thanks for your help guys I appreciate it.
Make sure you understand all that he said. You didn't seem to in previous
posts.
"Access uses -1 to represent true (but you can just use the value True)
which is why your code fails."

TRUE = -1
If you use it in any comparison it's safer to say:
IF something = True then

If the code is all yours then
If something Then
is also valid since the "expression" something will evaluate to True or
False.
 
Back
Top