Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

DMax and DMin rounding

Discussion in 'Information Technology' started by Cathy via AccessMonster.com, Nov 5, 2005.

  1. Cathy via AccessMonster.com

    Cathy via AccessMonster.com
    Expand Collapse
    Guest

    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.


    --
    Message posted via http://www.accessmonster.com
     
  2. Loading...

    Similar Threads Forum Date
    Remembering Narayanjot Kaur (spnadmin) Announcements Mar 29, 2016
    Welcoming New SPN Co-Administrator - Admin Kaur Sikh Sikhi Sikhism Jan 31, 2016
    Narayanjot Kaur Aka Spnadmin Some Memories Intellectual Articles Apr 28, 2015
    USA Meeting with the Transportation Security Administration (TSA) Breaking News Aug 2, 2014
    SPN Admin, Narayanjot Kaur, Passes Away. Celebrating Her Legacy Sikh Sikhi Sikhism Apr 29, 2014

  3. Steve Schapel

    Steve Schapel
    Expand Collapse
    Guest

    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.

    --
    Steve Schapel, Microsoft Access MVP


    Cathy via AccessMonster.com wrote:
    > 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.
    >
    >
     
  4. Cathy via AccessMonster.com

    Cathy via AccessMonster.com
    Expand Collapse
    Guest

    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 Schapel wrote:
    >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")



    --
    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access/200511/1
     
  5. Steve Schapel

    Steve Schapel
    Expand Collapse
    Guest

    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?)

    --
    Steve Schapel, Microsoft Access MVP


    Cathy via AccessMonster.com wrote:
    > 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
     
  6. Cathy via AccessMonster.com

    Cathy via AccessMonster.com
    Expand Collapse
    Guest

    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


    --
    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access/200511/1
     

Share This Page