VBA not producing decimals

  • Thread starter Thread starter Terri
  • Start date Start date
T

Terri

I have a form procedure in which I'm doing very simple math and would like a
calculation to produce a decimal to two places, but I'm not sure how to do
this in VBA. My code:

Dim intTmMin1 As Integer
Dim intTmMin2 As Integer
Dim intTmHr As Integer
Dim intRateTot As Double
Dim strMsg As String
On Error GoTo Err_AddNew_Click

'Update rate/hr
intRateTot = Nz([Abst_FullCase], 0) + Nz([Abst_AHI], 0)
intTmMin1 = Nz([AbstTmMin], 0)
intTmMin1 = (intTmHr * 60) + intTmMin1
intRateTot = (intRateTot \ intTmMin1)
Me!RatePerHr = intRateTot

It basically adds contents of some fields together to get a total, then
calculates total minutes, using an hour and minute numeric field. I'm
expecting the line

intRateTot = (intRateTot\intTmMin1|

to produce a decimal, but it rounds off, i.e. 135/105 produces 1 rather than
1.28.

I'm sure this is something very simple, but I can't seem to figure it out
:-0.

Thanks - Terri
 
Might be the backslash in

intRateTot = (intRateTot\intTmMin1|

Try changing the "\" to a "/"

The "\" perfoms integer only division.

John
 
Talk about something simple...that did it!

One other question - how do I now restrict the number of decimals to 2
places? I've set this in the underlying table and the form control, but I'm
still getting 14 decimal places.. Thanks again!!
--
Terri


John A. said:
Might be the backslash in

intRateTot = (intRateTot\intTmMin1|

Try changing the "\" to a "/"

The "\" perfoms integer only division.

John


Terri said:
I have a form procedure in which I'm doing very simple math and would like
a
calculation to produce a decimal to two places, but I'm not sure how to do
this in VBA. My code:

Dim intTmMin1 As Integer
Dim intTmMin2 As Integer
Dim intTmHr As Integer
Dim intRateTot As Double
Dim strMsg As String
On Error GoTo Err_AddNew_Click

'Update rate/hr
intRateTot = Nz([Abst_FullCase], 0) + Nz([Abst_AHI], 0)
intTmMin1 = Nz([AbstTmMin], 0)
intTmMin1 = (intTmHr * 60) + intTmMin1
intRateTot = (intRateTot \ intTmMin1)
Me!RatePerHr = intRateTot

It basically adds contents of some fields together to get a total, then
calculates total minutes, using an hour and minute numeric field. I'm
expecting the line

intRateTot = (intRateTot\intTmMin1|

to produce a decimal, but it rounds off, i.e. 135/105 produces 1 rather
than
1.28.

I'm sure this is something very simple, but I can't seem to figure it out
:-0.

Thanks - Terri
 
I think I figured this out. I had set the Format for this field as General,
but apparently setting the number of decimals does not work for the General
option. I changed this to Fixed and it seems to be working now...
--
Terri


Terri said:
Talk about something simple...that did it!

One other question - how do I now restrict the number of decimals to 2
places? I've set this in the underlying table and the form control, but I'm
still getting 14 decimal places.. Thanks again!!
--
Terri


John A. said:
Might be the backslash in

intRateTot = (intRateTot\intTmMin1|

Try changing the "\" to a "/"

The "\" perfoms integer only division.

John


Terri said:
I have a form procedure in which I'm doing very simple math and would like
a
calculation to produce a decimal to two places, but I'm not sure how to do
this in VBA. My code:

Dim intTmMin1 As Integer
Dim intTmMin2 As Integer
Dim intTmHr As Integer
Dim intRateTot As Double
Dim strMsg As String
On Error GoTo Err_AddNew_Click

'Update rate/hr
intRateTot = Nz([Abst_FullCase], 0) + Nz([Abst_AHI], 0)
intTmMin1 = Nz([AbstTmMin], 0)
intTmMin1 = (intTmHr * 60) + intTmMin1
intRateTot = (intRateTot \ intTmMin1)
Me!RatePerHr = intRateTot

It basically adds contents of some fields together to get a total, then
calculates total minutes, using an hour and minute numeric field. I'm
expecting the line

intRateTot = (intRateTot\intTmMin1|

to produce a decimal, but it rounds off, i.e. 135/105 produces 1 rather
than
1.28.

I'm sure this is something very simple, but I can't seem to figure it out
:-0.

Thanks - Terri
 
Back
Top