Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DO LOOP rs.BOF Problem 1

Status
Not open for further replies.

grgimpy

Programmer
Nov 1, 2006
124
US
I'm having trouble using the BOF function in a DO LOOP. [DirectPlate-BathChgCleaner] is a checkbox. I'm trying to loop through the recordset in order to determine the [DirectPlate-TotalSurfaceSqFt] value when the
[DirectPlate-BathChgCleaner] checkbox is True. This works fine except for when there is no True value for
[DirectPlate-BathChgCleaner] in the recordset.

I've included a BOF condition in my DO LOOP, but for some reason I get the "no current record" error when there is no record that meets the condition [DirectPlate-BathChgCleaner]=True. The error occurs on the "Do Until" line of my code. I'm trying to write this part of the code so I don't get errors when I first start using this database.

Any help would be greatly appreciated!

Code:
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("select [DirectPlate-Date/Time]," & _
        "[DirectPlate-TotalSurfaceSqFt]," & _
        "[DirectPlate-BathChgCleaner]," & _
        " from [Direct Plate PM Log]" & _
        " order by [DirectPlate-Date/Time]")

''''''DETERMINE TOTAL SQ FT
    CurrentTotalSqFt = _
        DSum("[DirectPlate-DJSurfaceSqFt]", "[Direct Plate Production Log]")
    
''''DETERMINE TOTAL SQUARE FEET
''''SINCE CLEANER BATH CHANGE
    rs.MoveLast
    Do Until rs![DirectPlate-BathChgCleaner] = True Or rs.BOF = True
        rs.MovePrevious
    Loop

    If Not rs.BOF = True Then
        Me.lblCleanerBathChg.Caption = _
        FormatNumber(CurrentTotalSqFt - rs![DirectPlate-TotalSurfaceSqFt], 0)
    Else
        Me.lblCleanerBathChg.Caption = "N/A"
    End If
 
well, this works:

Code:
    Do Until rs.BOF = True
        If rs![DirectPlate-BathChgCleaner] = True then Exit Do
        rs.MovePrevious
    Loop

But, I'd still like to know why my first attempt at the code doesn't work the same as this one. If anyone knows, please post for my own educational purposes. Thanks.
 
Do Until rs![DirectPlate-BathChgCleaner] = True Or rs.BOF = True
When .BOF is true there is no current record for testing rs![DirectPlate-BathChgCleaner] ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top