Checking value of checkbox

  • Thread starter noname101 via AccessMonster.com
  • Start date

N

noname101 via AccessMonster.com

Ok I know that this should be pretty simple but I'm losing my head over this.
I've seen examples of people checking the value of a checkbox in more than
one way, sometimes like CheckBox = True, CheckBox.Value = True, CheckBox = -1.
Just as a test I have one checkbox created on my form called chkAssets. I
have a command button that when I click should have a message box show up and
say "True" if the box is checked and the value is true. When I click the
command button I get the message: Object variable or With block variable not
set. What am I doing wrong am I missing a reference or something?

Heres the code:

Private Sub Command17_Click()
If chkAssets.Value = True Then
MsgBox "True"
End If
End Sub
 
Ad

Advertisements

G

Guest

I am not entirely sure what you are hoping to find out with this test, as
sometimes there are many ways of doing the same thing, its all down to the
programmer writing it.

But your if statement is missing its 'else'

try

Private Sub Command17_Click()
If chkAssets.Value = True Then
MsgBox "True"
Else
End If
End Sub
 
B

Bob Quintal

I am not entirely sure what you are hoping to find out with
this test, as sometimes there are many ways of doing the same
thing, its all down to the programmer writing it.

But your if statement is missing its 'else'

try

Private Sub Command17_Click()
If chkAssets.Value = True Then
MsgBox "True"
Else
End If
End Sub
Else in an if statement is optional. That is not the source of
the problem.

To the Original poster, try to reference chkAssets specifically
either with Forms!formname!chkAssets.value = true or the short
form Me!chkAssets = true
 
B

Bob Quintal

Ok I know that this should be pretty simple but I'm losing my
head over this. I've seen examples of people checking the
value of a checkbox in more than one way, sometimes like
CheckBox = True, CheckBox.Value = True, CheckBox = -1. Just as
a test I have one checkbox created on my form called
chkAssets. I have a command button that when I click should
have a message box show up and say "True" if the box is
checked and the value is true. When I click the command
button I get the message: Object variable or With block
variable not set. What am I doing wrong am I missing a
reference or something?

Heres the code:

Private Sub Command17_Click()
If chkAssets.Value = True Then
MsgBox "True"
End If
End Sub
as to the various ways of writing the test, Access defines true
as a numeric constant with a value of -1. so True and -1 are the
same thing. As to checkbox = True, this evaluates to -1 = -1,
which is -1, therefore is the same thing as just Checkbox, but
more work to compute.
and the .value property is the default for most controls, so if
you do not specify any property, that is the one used.
So again checkbox.value is the same as just checkbox.

Like in the old song... You say Tomaytoe, I say tomahtoe..
 
Ad

Advertisements

G

Guest

Thanks Bob
it appears i'm even more of a novice than i previoulsy thought
I'll have to keep studying

Falty
 

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

Similar Threads

Check a CheckBox 6
checkbox values 4
Checkbox Value 2
Checkbox values 3
Checkbox Default Values 1
CheckBox Transmitting values 1
Checkbox doesn't check in the form 6
Find and Replace checkbox values? 0

Top