Assigning yes/no a numeric value

eisoptrophobia

New member
Local time
Today, 02:33
Joined
Nov 12, 2007
Messages
3
Hi,
Complete newbie question, I have various yes/no boxes that i want to give a numeric value. The i want to add up these numbers and report it back to a text box.

Any help you can offer would be greatly appreciated.

Thanks in advance
Martin
 
in code you could just count the YESes...

dim i as integer

private function BoxCount(Box as boolean)

if box = true then
i = i + 1
else
i = i -1
end if

msgbox "You have " & i & " 'YES' count"

Stick that to execute on every box "on click" event like so:

BoxCount(me.<name of your box>)
 
Some code from a dbase of mine that should get you started


'Make a checkbox fill in a form field

This code goes in OnCurrent event of the form


Private Sub Form_Current()
On Error GoTo Form_Current_Err

'Checks YourYesNoField Field and Sets the YourTextField value

If Me.YourYesNoField = True Then
Me.YourTextField = 5
Else
Me.YourTextField = 15
End If

End Sub

This code goes in After Update event of the Checkbox


Private Sub YourYesNoField _AfterUpdate()
'After update event on YourYesNoField Checkbox
Form_Current
End Sub
 
Thanks for the fast responces guys. Nice feedback for a newbie.

Barrymk,
I can see how your code assignes a number and reports it back which is great thanks. However, i am after having a number of tick boxes with different values assigned and then i want to add those togther and report the total in a text box.

Any ideas on a way forward would be great.

Martin
 
same logic

lets say
box1 = 5
box2 = 10
box3 = 15


Private function BoxTotal(Box as integer)

dim total as integer

total = nz(total, 0) + box

me.textbox = total
me.refresh

end function

private sub box1_click()
if box1 = true then BoxTotal(5)
end sub
private sub box2_click()
if box2 = true then BoxTotal(10)
end sub
private sub box3_click()
if box3 = true then BoxTotal(15)
end sub


Thats assuming that all boxes will start unticked...
 
That's a neater and cleaner way to do it. Wish I'd had that when I was building my Db.
 
Erm, excuse me but yes/no is already numeric. No is stored as zero and yes is -1. So all you need to do is sum the field and change the sign and you get the number of yes values.
 
Erm, excuse me but yes/no is already numeric. No is stored as zero and yes is -1. So all you need to do is sum the field and change the sign and you get the number of yes values.

Thats the way i started but i was looking to assign a different value to each tick box. ie if tick box 1 = yes then i want a value of 20 associated to it.
 
e,

Use a query with fields like this:

Question1: IIf([Checkbox1], 5, 0)
Question2: IIf([Checkbox2], 10, 0)
Question3: IIf([Checkbox3], 10, 0)
Question4: IIf([Checkbox4], 20, 0)
GrandTotal: [Checkbox1]+[Checkbox2]+[Checkbox3]+[Checkbox4]

Then use the query for your form/report.
You do NOT have to show fields [Question1], [Question2] ... on your form/report
(unless you want to).

Wayne
 
Just an off-the-wall thought, but ... if you have non-standard check boxes, consider this: If you make a series of yes/no boxes as RADIO BUTTONS where the yes and no choices are BOTH visible, you can assign values to the buttons and then sum the values of the button group directly. Of course, "NO" would be 0? And "YES" can have any value you want assigned to it. Just remember, if you choose to do it this way, the button is associated with a value - but the .VALUE property is associated with the GROUP when you go Summing fields.
 

Users who are viewing this thread

Back
Top Bottom