Checking a box changes another value

JoeBunce

New member
Local time
Tomorrow, 00:06
Joined
Mar 18, 2010
Messages
1
Hello!
I'm currently working for charity that operates within a school in Tanzania, East Africa. Although my skill level in Access is currently completely zilch, I've been asked to try and set up an Access 97 database (running of an ancient Win 98 computer) to replace the existing masses of paper files that deal with the 'hardship fund'.
I'm moderately competent at fiddling around to work things out, but I've come unstuck.
Put simply, I am creating a form that consists of many Yes/No checkboxes ("Box#") and a single Number ("Total") textbox. The idea is that, upon clicking each checkbox, a value is added to the current value of the "Total" box.
I originally attempted this code:
Code:
Private Sub Box1_Click ()
 Total.Value = Total.Value + 500
End Sub
The problem arises when you try to uncheck the checkbox: it continues to add the 500 whether you're checking or unchecking the box. Thus I tried:
Code:
Private Sub Box1_Click ()
If Box1 = "No" Then Total.Value = Total.Value + 500 
 Else Total.Value = Total.Value - 500
End Sub
But that ended up with an utterly baffling "Else without If" error. So I tried:
Code:
Private Sub Box1_Click ()
If Box1 = "No" Then Total.Value = Total.Value + 500
If Box1 = "Yes" Then Total.Value = Total.Value - 500
End Sub
In this case, Access both added and subtracted the 500, obviously with a net result of nada.
You may laugh at my efforts, but I've only been using Access a couple of hours, so please, pity me and help!
Thank you,
Joe Bunce
Tanzania
 
Last edited:
Hi,

Try this:

Private Sub Box1_Click ()

If Box1.Value = True Then
Total.Value = Total.Value + 500
Else
Total.Value = Total.Value - 500
End If

End Sub
 
Last edited:
You should use the after update event of the check box.

Also, Yes = -1 and No = 0
 

Users who are viewing this thread

Back
Top Bottom