Access checkboxes: point values as decimals

C

colvind

Hi folks. I've got a form with a bunch of checkoxes that are worth
varying numbers of points, i.e. some check boxes are worth 5 points,
some worth 12, etc..
I also have a total points earned box at the bottom of the form.
The function I've created/modified works and as you check or uncheck
the checkboxes, the value in the tally box increases or decreases.

However, one item I've still stumbling on.
One of the checkbox values is 2.5. But for whatever reason, only 2 is
included in the tally. The .5 gets left off. There are four check
boxes worth 2.5. When all checkboxes are checked, the tally should
add to 100. But because the .5's aren't being read, the final tally
only adds to 98.

Is it just I need to express the decimaled value differently in my
function?
Below is the function text for the first 4 checkboxes:
Ctl1_1 is the name of a checkbox, same as Ctl1_2, etc

If Me.Ctl1_1 = True Then
lngItem1Val = 2
Else
lngItem1Val = 0
End If
If Me.Ctl1_2 = True Then
lngItem2Val = 2.5
Else
lngItem2Val = 0
End If
If Me.Ctl1_3 = True Then
lngItem3Val = 2
Else
lngItem3Val = 0
End If
If Me.Ctl1_4 = True Then
lngItem4Val = 2.5
Else
lngItem4Val = 0


Do I need to express the decimal value differently in my function?
 
F

fredg

Hi folks. I've got a form with a bunch of checkoxes that are worth
varying numbers of points, i.e. some check boxes are worth 5 points,
some worth 12, etc..
I also have a total points earned box at the bottom of the form.
The function I've created/modified works and as you check or uncheck
the checkboxes, the value in the tally box increases or decreases.

However, one item I've still stumbling on.
One of the checkbox values is 2.5. But for whatever reason, only 2 is
included in the tally. The .5 gets left off. There are four check
boxes worth 2.5. When all checkboxes are checked, the tally should
add to 100. But because the .5's aren't being read, the final tally
only adds to 98.

Is it just I need to express the decimaled value differently in my
function?
Below is the function text for the first 4 checkboxes:
Ctl1_1 is the name of a checkbox, same as Ctl1_2, etc

If Me.Ctl1_1 = True Then
lngItem1Val = 2
Else
lngItem1Val = 0
End If
If Me.Ctl1_2 = True Then
lngItem2Val = 2.5
Else
lngItem2Val = 0
End If
If Me.Ctl1_3 = True Then
lngItem3Val = 2
Else
lngItem3Val = 0
End If
If Me.Ctl1_4 = True Then
lngItem4Val = 2.5
Else
lngItem4Val = 0

Do I need to express the decimal value differently in my function?

You appear to have declared all the lngItemXVal variables as a Long
Integer (you haven't included the declaration here in this post, so
I'm guessing the lng prefix is for Long.).
By definition, an Integer cannot have a decimal value.
Dim your variables as Double.
 
L

Linq Adams via AccessMonster.com

Your names such as

lngItem4Val

would indicate that they are defined as Long Integers, which basically means
they are ***whole numbers*** and cannot contain decimals. Change the datatype
of all variables to Double and if the total box is unbound, set its format to
General Number.
 
J

John W. Vinson

However, one item I've still stumbling on.
One of the checkbox values is 2.5. But for whatever reason, only 2 is
included in the tally. The .5 gets left off. There are four check
boxes worth 2.5. When all checkboxes are checked, the tally should
add to 100. But because the .5's aren't being read, the final tally
only adds to 98.

You're apparently calculating the value in a Long Integer field. An Integer
is, by definition, a whole number with no fractional portion.

Use a Single or Double instead.
 

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

Top