Checkbox Totals

BobJ

Kestrel - Crawley
Local time
Today, 08:09
Joined
Mar 22, 2007
Messages
47
Hi,

Im trying to make my checkbox have a value of 10 so that when it is checked it adds £10 to my total.. Ive searched the forums and read 20 odd threads but they didnt seem to be of any help..

my checkbox is linked to a yes/no field called congestioncharge in a table called orders.

ive tried to make the default value 10, but as my coding is virtually non-existant (im learning) i cant seem to finish off the process.

I would greatly appreciate any help!

Cheers,

bob
 
A checkbox only has a value of -1 (for True) or 0 (for False), so a default of 10 has no meaning to it. If you add this code, to your check box's AfterUpdate event, it should do what you want:

Code:
If Me.congestioncharge = True Then
   Me.YourTextBoxNameWithYourPoundsTotalHere = Me.YourTextBoxNameWithYourPoundsTotalHere + 10
End If

Now, if you need to subtract 10 if it is checked and then unchecked it would be
Code:
If Me.congestioncharge = True Then
   Me.YourTextBoxNameWithYourPoundsTotalHere = Me.YourTextBoxNameWithYourPoundsTotalHere + 10
Else
   Me.YourTextBoxNameWithYourPoundsTotalHere = Me.YourTextBoxNameWithYourPoundsTotalHere -10

End If
 
thanks for the reply bob!

i tried what you suggested and i got a run time error saying "you cant assign a value to this object"

wheni click on debug this line is highlighted:

Me.Total = Me.Total + 10

(total is the name of the textbox)

the code lokos like this:

Private Sub Check122_AfterUpdate()
If Me.CongestionCharge = True Then
Me.Total = Me.Total + 10
End If
End Sub
 
You probably have a formula as the recordsource for the text box "Total." So, I would put a hidden text box on the form, name it something like txtCC and then set the formula in the Total box to include adding that text box to the total and then in your code set it to
Code:
Private Sub Check122_AfterUpdate()
If Me.CongestionCharge = True Then
   Me.txtCC = 10
Else
   Me.txtCC = 0
End If
Me.Recalc
End Sub
 
haha you absolute genius! :)

thanks a million works perfectly!
 

Users who are viewing this thread

Back
Top Bottom