Calculation - fractions/decimals

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a small snippet of code in a text box on my form:

Private Sub txtTotal1_Enter()
Me.txtTotal1 = (Nz([txtItem1Units], 0) * Me.cboItem1Desc.Column(1)) *
Me.cboItem1Desc.Column(2)
End Sub

Column 1 of the cboItem1Desc is a value (price in fact), column 2 is a
fraction (markup). Calculations using column 1 work fine, no problems.
Calculations using column 2 do not happen at all. Why would this be? Both
formats are exactly the same for the underlying entries in the table!!
 
Are you sure that Column(1) and Column(2) are the columns you want? Is your
ColumnCount 3 (or more) for this Combo Box? The Column index starts at 0.

Good Luck!
 
Yep, there are three columns, with 0 being the bound column for the control.
I know Column 1 is correct because I use that in a previous calculation and
it works fine. Also when I susbsitute Column 2 for Column 1 it works, it
just seems to have issues with decimals but I can't for the life of me work
out why...!

Chaim said:
Are you sure that Column(1) and Column(2) are the columns you want? Is your
ColumnCount 3 (or more) for this Combo Box? The Column index starts at 0.

Good Luck!
--
Chaim


Aaron Howe said:
I have a small snippet of code in a text box on my form:

Private Sub txtTotal1_Enter()
Me.txtTotal1 = (Nz([txtItem1Units], 0) * Me.cboItem1Desc.Column(1)) *
Me.cboItem1Desc.Column(2)
End Sub

Column 1 of the cboItem1Desc is a value (price in fact), column 2 is a
fraction (markup). Calculations using column 1 work fine, no problems.
Calculations using column 2 do not happen at all. Why would this be? Both
formats are exactly the same for the underlying entries in the table!!
 
Aaron said:
I have a small snippet of code in a text box on my form:

Private Sub txtTotal1_Enter()
Me.txtTotal1 = (Nz([txtItem1Units], 0) * Me.cboItem1Desc.Column(1)) *
Me.cboItem1Desc.Column(2)
End Sub

Column 1 of the cboItem1Desc is a value (price in fact), column 2 is a
fraction (markup). Calculations using column 1 work fine, no problems.
Calculations using column 2 do not happen at all. Why would this be? Both
formats are exactly the same for the underlying entries in the table!!


What do you mean when you say "Calculations using column 2
do not happen at all"

The "extra" columns in a combo/list box are test strings,
maybe there's an issue converting them to a numeric valuse??
 
Both Column 1 and Column 2 are Number values in the table, and the controls
are set for the "Standard" format (I have tried changing Column 2 to
"Decimal" but that shouldn't make a difference). Essentially they are
identical.

When I carry out calculations using Column 1 (a whole number) they work
fine, but calcultions using Column 2... nothing. Not an error, just -
nothing!

Marshall Barton said:
Aaron said:
I have a small snippet of code in a text box on my form:

Private Sub txtTotal1_Enter()
Me.txtTotal1 = (Nz([txtItem1Units], 0) * Me.cboItem1Desc.Column(1)) *
Me.cboItem1Desc.Column(2)
End Sub

Column 1 of the cboItem1Desc is a value (price in fact), column 2 is a
fraction (markup). Calculations using column 1 work fine, no problems.
Calculations using column 2 do not happen at all. Why would this be? Both
formats are exactly the same for the underlying entries in the table!!


What do you mean when you say "Calculations using column 2
do not happen at all"

The "extra" columns in a combo/list box are test strings,
maybe there's an issue converting them to a numeric valuse??
 
The control's Format property has nothing to do with what's
returned by the Column(x) property. Even if the columns are
all digits doesn't mean that the Column(x) property returns
a number type value. Although I would expect Access to
convert the returned string to a number automatically, try
converting it explicitly:

.. . . + CDbl(Me.cboItem1Desc.Column(2))

Also, double check that the column value is not blank.
--
Marsh
MVP [MS Access]



Aaron said:
Both Column 1 and Column 2 are Number values in the table, and the controls
are set for the "Standard" format (I have tried changing Column 2 to
"Decimal" but that shouldn't make a difference). Essentially they are
identical.

When I carry out calculations using Column 1 (a whole number) they work
fine, but calcultions using Column 2... nothing. Not an error, just -
nothing!

Aaron said:
I have a small snippet of code in a text box on my form:

Private Sub txtTotal1_Enter()
Me.txtTotal1 = (Nz([txtItem1Units], 0) * Me.cboItem1Desc.Column(1)) *
Me.cboItem1Desc.Column(2)
End Sub

Column 1 of the cboItem1Desc is a value (price in fact), column 2 is a
fraction (markup). Calculations using column 1 work fine, no problems.
Calculations using column 2 do not happen at all. Why would this be? Both
formats are exactly the same for the underlying entries in the table!!
Marshall Barton said:
What do you mean when you say "Calculations using column 2
do not happen at all"

The "extra" columns in a combo/list box are test strings,
maybe there's an issue converting them to a numeric valuse??
 
I tried that out, and I get the error "Invalid use of Null" - which indicates
Access is treating the fraction/decimal as a zero value...?!

Marshall Barton said:
The control's Format property has nothing to do with what's
returned by the Column(x) property. Even if the columns are
all digits doesn't mean that the Column(x) property returns
a number type value. Although I would expect Access to
convert the returned string to a number automatically, try
converting it explicitly:

.. . . + CDbl(Me.cboItem1Desc.Column(2))

Also, double check that the column value is not blank.
--
Marsh
MVP [MS Access]



Aaron said:
Both Column 1 and Column 2 are Number values in the table, and the controls
are set for the "Standard" format (I have tried changing Column 2 to
"Decimal" but that shouldn't make a difference). Essentially they are
identical.

When I carry out calculations using Column 1 (a whole number) they work
fine, but calcultions using Column 2... nothing. Not an error, just -
nothing!

Aaron Howe wrote:
I have a small snippet of code in a text box on my form:

Private Sub txtTotal1_Enter()
Me.txtTotal1 = (Nz([txtItem1Units], 0) * Me.cboItem1Desc.Column(1)) *
Me.cboItem1Desc.Column(2)
End Sub

Column 1 of the cboItem1Desc is a value (price in fact), column 2 is a
fraction (markup). Calculations using column 1 work fine, no problems.
Calculations using column 2 do not happen at all. Why would this be? Both
formats are exactly the same for the underlying entries in the table!!
Marshall Barton said:
What do you mean when you say "Calculations using column 2
do not happen at all"

The "extra" columns in a combo/list box are test strings,
maybe there's an issue converting them to a numeric valuse??
 
I found it, I had missed the column count in the combobox properties - can't
believe it was something so small and stupid! Anyway it works now, though I
don't quite understand why the first bound column worked and not the second -
but there you go.

Aaron Howe said:
I tried that out, and I get the error "Invalid use of Null" - which indicates
Access is treating the fraction/decimal as a zero value...?!

Marshall Barton said:
The control's Format property has nothing to do with what's
returned by the Column(x) property. Even if the columns are
all digits doesn't mean that the Column(x) property returns
a number type value. Although I would expect Access to
convert the returned string to a number automatically, try
converting it explicitly:

.. . . + CDbl(Me.cboItem1Desc.Column(2))

Also, double check that the column value is not blank.
--
Marsh
MVP [MS Access]



Aaron said:
Both Column 1 and Column 2 are Number values in the table, and the controls
are set for the "Standard" format (I have tried changing Column 2 to
"Decimal" but that shouldn't make a difference). Essentially they are
identical.

When I carry out calculations using Column 1 (a whole number) they work
fine, but calcultions using Column 2... nothing. Not an error, just -
nothing!


Aaron Howe wrote:
I have a small snippet of code in a text box on my form:

Private Sub txtTotal1_Enter()
Me.txtTotal1 = (Nz([txtItem1Units], 0) * Me.cboItem1Desc.Column(1)) *
Me.cboItem1Desc.Column(2)
End Sub

Column 1 of the cboItem1Desc is a value (price in fact), column 2 is a
fraction (markup). Calculations using column 1 work fine, no problems.
Calculations using column 2 do not happen at all. Why would this be? Both
formats are exactly the same for the underlying entries in the table!!


:
What do you mean when you say "Calculations using column 2
do not happen at all"

The "extra" columns in a combo/list box are test strings,
maybe there's an issue converting them to a numeric valuse??
 
Back
Top