Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    thanks for the prompt minty, this is something i should be able to do with one eye closed but a little brain freeze............



    i will come back to it but as always sometimes a nudge is required so that is appreciated

  2. #17
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Dave,
    Try this please, you need to store the previous record's value:
    Code:
    Dim rs As dao.Recordset    
    Dim curRate As Currency, curDiff As Currency, curFuelPrice As Currency, curAvg As Currency, curMax As Currency
    Dim i As Integer
    Dim curPrevious as  Currency    
        
        
        
            Set rs = CurrentDb.OpenRecordset("Select * From tblFuelPrices Order By MonthStart")
                
                With rs
                
                curPrevious=!FuelPrice 'first record
                Do While Not rs.EOF            
                    curDiff = !FuelPrice-curPrevious                    
                    rs.Edit
                    !Difference = curDiff
                    .Update
                    curPrevious=!FuelPrice
                    rs.MoveNext            
                Loop
                
                End With
    Set rs = Nothing
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #18
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Thank You Vlad, will read your method and test

  4. #19
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Vlad you absolute legend

    That done the trick, my final part now is there is a field called PercentDiff, now calculate the percentage within that loop, i have a few various percentage formulas saved so i am now going to test some of my formulas to complete the additional data for this project

    Thanks again

  5. #20
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Hi Vlad, all sorted, i think sometimes i just brain freeze on calculations and when to put variables inside and/or outside of a loop

    This is all working with an addition percentage and differences, project complete

    Code:
        Dim rs As dao.Recordset    Dim curRate As Currency, curDiff As Currency, curFuelPrice As Currency, curAvg As Currency, curMax As Currency, curPrevious As Currency
        Dim i As Integer
        Dim dblPercent As Double
        Dim curOrgPrice As Currency, curNewPrice As Currency
        
            Set rs = CurrentDb.OpenRecordset("Select * From tblFuelPrices Order By MonthStart")
                
                With rs
                curOrgPrice = "1234" ' Example of current price
                
                curPrevious = !FuelPrice 'first record
                Do While Not rs.EOF
                    
                    
                    curDiff = !FuelPrice - curPrevious
                    dblPercent = curDiff / !FuelPrice
                    curNewPrice = curDiff / 4 '25% of difference
                    
                    rs.Edit
                    !Difference = curDiff
                    !PercentageDiff = dblPercent
                    !orgCharge = curOrgPrice
                    !ChargeDiff = curNewPrice
                    
                If curNewPrice < curPrevious Then
                    !NewCharge = curOrgPrice + curNewPrice
                    Else
                    !NewCharge = curOrgPrice - curNewPrice
                End If
                    
                    .Update
                    dblPercent = !PercentageDiff
                    curPrevious = !FuelPrice
                    rs.MoveNext
                Loop
                
                End With
    Set rs = Nothing

  6. #21
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Dave, glad to see you got it working and posted the working code!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-12-2020, 04:19 AM
  2. Replies: 2
    Last Post: 02-13-2017, 02:40 PM
  3. Replies: 3
    Last Post: 08-18-2012, 03:25 AM
  4. Replies: 1
    Last Post: 06-15-2012, 05:51 PM
  5. Replies: 2
    Last Post: 05-17-2012, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums