Avatar of rsburge
rsburge
Flag for United States of America asked on

Help Adjusting the Update Piece of Access VBA Code

Hello Experts - The code below is working perfectly, however there has been a change in rules and an adjustment to the code is needed.

I need to adjust this With statement so that if there is only 1 record returned in the recordset, the bytPoints value for that record is 5 instead of 10.


Dim bytPoints As Byte
bytPoints = 10
strSQL = strSQLbr1
With CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
    Do Until .EOF
        .Edit
        If !RCER_TotalTime = 100 Then
            !RCER_Points_AG = 0
            .Update
        End If
        If !RCER_TotalTime < 100 Then
            !RCER_Points_AG = bytPoints
            .Update
        End If
        If bytPoints > 0 Then bytPoints = bytPoints - 1
        .Edit: !RCER_Rank_AG = .AbsolutePosition + 1: .Update
        .MoveNext
    Loop
End With

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
Dale Fye

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rsburge

ASKER
I am not 100% sure...  this was provided by another expert last year.  The associated question is here...

https://www.experts-exchange.com/questions/27115570/Update-Table-Field-Counting-Backwards-from-10.html
Jeffrey Coachman

<Why are you using the Byte datatype, instead of Integer?>
Perhaps because the value may never go over 255 and they don't need negatives...?
rsburge

ASKER
fyed - testing now...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Dale Fye

You might also consider:

Dim bytPoints As Byte
strSQL = strSQLbr1
With CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

    if not .eof then
        .movelast
        bytPoints = iif(.RecordCount = 1, 5, 10)
        .movefirst
    endif

    Do Until .EOF
        .Edit
        !RCER_Points_AG =  iif(!RCER_TotalTime = 100, 0, bytPoints)
        !RCER_Rank_AG = .AbsolutePosition + 1
        .Update
        If bytPoints > 0 Then bytPoints = bytPoints - 1
        .MoveNext
    Loop
End With
rsburge

ASKER
Thank you!  This works great!
Dale Fye

Personally, I would actually go with the 2nd version.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.