Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Recordsets and the First Record
Colin Eastaugh 
     
44 days ago
Courtesy of Richard's Fitness 52 video, the VBA code below toggles a check box, everything works fine excepting the first record.

Default value for the individual records check box is TRUE.

FIRST press of the button - changes FIRST record check box to FALSE, ALL OTHER records remain TRUE
SECOND press of the button - changes FIRST record check box to TRUE, ALL OTHER records change to FALSE
THIRD press of the button - changes FIRST record check box to FALSE, ALL OTHER records change to TRUE

And so on, alternating between the SECOND and THIRD presses, the FIRST record is marching out of tune with the rest of the records.

Does anyone have any idea what is happening? I would be quite happy to use a wraparound solution, treating the FIRST record differently to the other records but I don't seem to be able to use rs.FindFirst correctly.

Private Sub Command23_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(SQL)
Do While Not rs.EOF
If rs!YN = YN Then
    rs.Edit
    rs!YN = Not rs!YN
    rs.Update
Else
    Exit Do
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Me.Requery
End Sub
Sandra Truax  @Reply  
         
44 days ago
I think the problem is this line:  If rs!YN = YN Then

Try storing the original value in a variable before the loop starts.

DetailsDim rs As DAO.Recordset
    Dim OldValue As Boolean
    
    OldValue = Nz(Me!YN, False)
    
    Set rs = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)
    
    Do While Not rs.EOF
        If Nz(rs!YN, False) = OldValue Then
            rs.Edit
            rs!YN = Not rs!YN
            rs.Update
        Else
            Exit Do
        End If
        rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    
    Me.Requery

End Sub


Donald Blackwell  @Reply  
       
44 days ago
If Sandra's code doesn't help, then we would probably need to see your SQL statement since your code is similar to the HasEaten_MouseDown event in the Fitness series other than being for the click event... Well, and that Richard "Set It", but didn't "Forget It" with his recordset in that procedure.
Colin Eastaugh OP  @Reply  
     
44 days ago
Sandra - you are a star, many thanks, your suggestion has worked.  A sunny day in London, you have made it even sunnier.  All the best - Colin
Sandra Truax  @Reply  
         
44 days ago
Colin I'm glad it worked for you
Colin Eastaugh OP  @Reply  
     
44 days ago
Donald - thanks for your comments, Sandra's suggestion has worked, touch wood.  I'll no doubt be back with a question about the legendary Fitness 51 video soon.  All the best - Colin

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/20/2026 10:04:40 PM. PLT: 1s