DMax and DMin rounding

  • Thread starter Cathy via AccessMonster.com
  • Start date
C

Cathy via AccessMonster.com

Hi,
I have the following code for some calculations. The code works fine for
whole numbers, however if I have decimal entries, both DMax and DMin round
the numbers and my calculations are then way off. It's odd that DAvg doesn't
round the numbers. I've tried using Format, but doesn't appear to be working.
Any suggestions?

' Calculations on the test table
Dim docal As Double
Dim docal2 As Double
Dim docal3 As Double

docal = DMax("[DOcalc]", "stabilization_calcs", "[DOcalc]")
docal2 = DMin("[DOcalc]", "stabilization_calcs", "[DOcalc]")
docal3 = DAvg("[DOcalc]", "stabilization_calcs", "[DOcalc]")

Thanks in advance.
 
S

Steve Schapel

Cathy,

It is not clear what you are trying to do with the 3rd argument in the
domain functions. I suspect you just mean like this...
DMax("[DOcalc]","stabilization_calcs")

Is stabilization_calcs a query? And is DOcalc the name of a calculated
field in that query. I suspect that the calculation of the DOcalc value
in the stabilization_calcs query is where the rounding is taking place,
and not in the domain functions (DMax etc). Can you please check this?
Otherwise, can you please let us know what are the calculations where
the problem is occurring? I mean, what happens in your code with the
docal, docal2, docal3 variables after the bit you already showed? Thanks.
 
C

Cathy via AccessMonster.com

Hi Steve,

Sorry for the confusion. I left off the final calculation on my code....it
should be:

' Calculations on the test table
Dim docal As Long
Dim docal2 As Double
Dim docal3 As Double

docal = DMax("[DOcalc]", "stabilization_calcs","[DOcalc]")
MsgBox "dmax " & docal
docal2 = DMin("[DOcalc]", "stabilization_calcs","[DOcalc]")
MsgBox "dmin " & docal
docal3 = DAvg("[DOcalc]", "stabilization_calcs","[DOcalc]")
MsgBox "ave " & docal
DO_Stab = ((docal - docal2) / docal3) * 100

Also to give you more of a background on what I'm trying to do.... I have a
data entry form which allows users to enter values for certain parameters, DO
being one of them, for a period of time until stabilization has occured. To
determine if stabilization has occured, I need to calculate a reference
number from the last 3 DO entries. I've created a recordset to scroll thru
my table, assign the last 3 readings to 3 variables which are then written to
[DOcal] in "stabilization_calcs". I now have my last 3 DO readings and can
do the calculation (as seen above). Throughout my code, I'd included message
boxes to make sure I was getting the correct results. All the message boxes
showed my results as 4.5, 5 and 5.1 prior to doing the final calcuations
above. However, the message boxes I have after docal = DMAx and docal2=
DMin, show the numbers as rounded ( 5.1 to appears as 5 and 4.5 to 4), which
then throws off my final DO_stab calculation by quite a bit. The odd thing
is the DAvg does not round the number....it appears as 4.6667....

Hope this helps a bit.....Thanks again. Cath

Steve said:
Cathy,

It is not clear what you are trying to do with the 3rd argument in the
domain functions. I suspect you just mean like this...
DMax("[DOcalc]","stabilization_calcs")
 
S

Steve Schapel

Cathy,

As I mentioned before, there is a syntax error in your dpmain functions:
DMax("[DOcalc]", "stabilization_calcs","[DOcalc]") doesn't make sense.
What is the meaning of the "[DOcalc]" in the 3rd argument of the function?

As I suggested before, I suggest you check the values of the [DOcal]
field in stabilization_calcs, which now appears to be a table, not a
query (am I right?)
 
C

Cathy via AccessMonster.com

Steve,

Yes, the stabilization_calc is a table, not a query....didn't think to look
at the field defs in the table....They were set up as Long Integer. I
changed them to Double and now things are working as they should....

As for the 3rd argument....there is no meaning, so I removed it.....

Thanks again.

Cath
 

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