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 Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Recordset Woes
Sandra Truax 
         
2 years ago
Could someone please give me some help?  When I msgbox TodayOfWeek I get 6. When I msgbox rs!SortOrder.Value, I get a 6.  When I run the code, nothing. If I change rs!SortOrder.Value to "6", it highlightes all the records, not the ones that the SortOrder is a 6.

DetailsPrivate Sub SortOrderBackgroundColor()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim todayOfWeek As Integer
    Dim ctl As Control
    
    Set db = currentDB
    Set rs = db.OpenRecordset("ChecklistT")
    todayOfWeek = Weekday(Date)
    MsgBox todayOfWeek
    Do While Not rs.EOF
        If todayOfWeek = rs!SortOrder.Value Then
            MsgBox rs!SortOrder.Value
            Me.Controls("SortOrder").BackColor = RGB(255, 255, 0) 'Yellow
        Else
            Me.Controls("SortOrder").BackColor = RGB(191, 191, 191) '#BFBFBF
        End If
        rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    Set db = Nothing
End Sub
Adam Schwanz  @Reply  
           
2 years ago
What is this recordset doing? The recordset should be a collection of data not interacting with the form really.

Usually when I'm interacting with the form colors I'd do something like

    Dim Ctl As Control
    For Each Ctl In Me.Controls
        If TypeOf Ctl Is TextBox Or TypeOf Ctl Is ComboBox Then
            If Ctl.Locked = True Then
                Ctl.BackColor = RGB(225, 225, 225)
            ElseIf Ctl.Locked = False Then
                Ctl.BackColor = RGB(255, 255, 255)
            End If
        End If
    Next Ctl
Sandra Truax OP  @Reply  
         
2 years ago
This is what I'm trying to do, and the result that I posted was from ChatGPT.

Write VBA for Private Sub SortOrderBackgroundColor() that will change the background color of the field "SortOrder"  for all records as follows:

Set all to #BFBFBF.  
If today is a MONDAY and SortOder = 1, then set the background color of SortOrder to yellow
If today is a Tuesday and SortOder = 2, then set the background color of SortOrder to yellow
If today is a Wednesday and SortOder = 3, then set the background color of SortOrder to yellow
If today is a Thursday and SortOder = 4, then set the background color of SortOrder to yellow
If today is a Friday and SortOder = 5, then set the background color of SortOrder to yellow
If today is a Saturday and SortOder = 6, then set the background color of SortOrder to yellow
Richard Rost  @Reply  
          
2 years ago
So you're only really dealing with one field here, right? SortOrder? And it has a value from 1 to 7 based on the day of the week? You've got 1=Monday, whereas normally 1=Sunday, so that's OK. We just need a little math.

SortOrder.BackColor = vbWhite ' or whatever you want
If Weekday(Date())=SortOrder+1 Then SortOrder.BackColor = vbRed ' or whatever


That should do it. No Ifs, Recordsets, For Each, Controls, etc. needed.
Adam Schwanz  @Reply  
           
2 years ago
Is this a continuous form?

Conditional formatting might be better for this, could you upload a picture so i can try to see what your doing on the form?
Richard Rost  @Reply  
          
2 years ago
Oh, yes, CF would be REQUIRED for a continuous form. In that case, just use my logic for the CF formula.
Sandra Truax OP  @Reply  
         
2 years ago

Richard Rost  @Reply  
          
2 years ago
Yeah. Use Conditional Formatting. Value = Weekday(Date-1)

It would be even easier if you made Monday=2. Just sayin.
Sandra Truax OP  @Reply  
         
2 years ago
Thanks Rick, I'll see if I can figure that out because it is a continuous form.
Sandra Truax OP  @Reply  
         
2 years ago
And making Monda a 2 is not a problem.  
Richard Rost  @Reply  
          
2 years ago
Yeah, only because with the Weekday function, the start of the week (Sunday) is 1, you can change that with the options, but it's just easier if you deal with what they give you. Then just have the conditional formatting say if today's weekday is the same as the value in this field, then change the color.
Sandra Truax OP  @Reply  
         
2 years ago
Thank you Adam and Richard.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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/6/2026 11:25:35 AM. PLT: 0s