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 Project Management    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
FormatConditions
Caleb Hansen 
        
3 years ago
Richard-

I'm not patient enough to wait, so I started tanking this on my own to see If I can get it done. I'm hoping that you can easily tell me where I may be going awry here. I created a table to store the individual box data. I added 3 types of fields for each of the boxes. "Box00H, Box01H,..." is for a quantity of hours that a task or job will take in the given timescale of the chart. I set each Boxes record source to the "Box00H" fields. The other 2 types of fields are like this: "Box00ColorID, Box01ColorID,..." to store the ColorID for referencing the Hex#'s in the ColorT, and then "Box00Date, Box01Date,..." to store the date value of each box. Then I wrote the below for the BoxClick. It keeps getting hung up on rs1.edit saying that the record is locked from another session on the machine, but I've closed absolutely anything that might have interfered and I still get the error. I have the form based on a query as you had done, and I'm able to change the values in the various fields no problem, even with the form open. I'm stumped.

Private Sub DoMouseClick(BoxNum As Integer, Shift As Integer)

    Dim ColorFld As String, DateFld As String, boxName As String
    Dim X As Integer
    Dim backColor As Long, foreColor As Long, currentColorID As Long
    Dim rs1 As Recordset, rs2 As Recordset
    Dim dateValue As Date
    Dim FC As FormatCondition
    Dim boxControl As Control

    If IsLocked Or IsNull(JobName) Then Exit Sub

    If TimeframeCombo = "Day" Then
        dateValue = TargetDate + BoxNum
    ElseIf TimeframeCombo = "Week" Then
        dateValue = TargetDate + (BoxNum * 7)
    End If
    
    If Shift Then
        WorkEnd = dateValue
    Else
        WorkStart = dateValue
    End If

    If WorkEnd < WorkStart Then WorkEnd = WorkStart
    If IsNull(WorkStart) Then WorkStart = WorkEnd
    If IsNull(WorkEnd) Then WorkEnd = WorkStart
    
    ' open main recordset
    Set rs1 = CurrentDb.OpenRecordset("SELECT * FROM TempScheduleT WHERE TempScheduleID =" & Me.TempScheduleID)

    For X = 0 To 20
        
        boxName = "Box" & Format(X, "00")
        
        Set boxControl = Me.Controls(boxName)
        boxControl.FormatConditions.Delete
        
        ColorFld = boxName & "ColorID"
        DateFld = boxName & "Date"

        rs1.Edit
        
        'set DateFld
        If TimeframeCombo = "Day" Then
            rs1.Fields(DateFld) = TargetDate + X
        ElseIf TimeframeCombo = "Week" Then
            rs1.Fields(DateFld) = TargetDate + (X * 7)
        End If
        
        'set ColorFld
        If rs1.Fields(DateFld) >= Me.WorkStart And rs1.Fields(DateFld) <= Me.WorkEnd Then
            ' Set to the selected ColorID for in-range:
            rs1.Fields(ColorFld) = Me.ColorID
        Else
            ' Set to ColorID #1 for out-of-range:
            rs1.Fields(ColorFld) = 1
        End If
        
        ' Fetching the ColorID for the current box:
        currentColorID = Nz(rs1.Fields(ColorFld), 1) ' Default to 1 if null

        ' Fetching actual colors based on the ColorID:
        Set rs2 = CurrentDb.OpenRecordset("SELECT TextBackColor, TextForeColor FROM ColorT WHERE ColorID = " & currentColorID, dbOpenSnapshot)
        Set FC = boxControl.FormatConditions.Add(acExpression, acEqual, "[ColorID]=" & currentColorID)
        FC.backColor = HexToRGB(rs2!TextBackColor)
        FC.foreColor = HexToRGB(rs2!TextForeColor)
        
        rs2.Close
        Set rs2 = Nothing
        
        rs1.Update

    Next X
    
    rs1.Close
    Set rs1 = Nothing


    ' Refresh the form to trigger the Current event
    Me.Requery
    
End Sub


Private Sub Box00_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    DoMouseClick 0, Shift

End Sub

Private Sub Box01_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    DoMouseClick 1, Shift

End Sub

..........
Adam Schwanz  @Reply  
           
3 years ago
Can you upload an image of the table? I'm having a hard time following what your saying with the table setup.

Few things I see,

This section here looks like it should always calculate to WorkStart and WorkEnd being the same time, regardless of what order you put them in, is that right? Unless you're also inserting them from another area before this code fires.

    If Shift Then 'this would set one or the other values and leave the other blank
        WorkEnd = dateValue
    Else
        WorkStart = dateValue
    End If
'This below would set the other one to the same time regardless of how the previous section went, might as well just say 'WorkEnd=datevalue
'WorkStart=datevalue
    If WorkEnd < WorkStart Then WorkEnd = WorkStart
    If IsNull(WorkStart) Then WorkStart = WorkEnd
    If IsNull(WorkEnd) Then WorkEnd = WorkStart

I would add a Me.Refresh right before you set the recordset, since you just changed values in the record, it's going to be dirty.

Try that and see if it changes anything
Caleb Hansen OP  @Reply  
        
3 years ago
I figured it out. I was super tired last night and was banging my head around trying to figure this out. Then I woke up this morning and realized it was because I changed the forms boxes to be unlocked so I can fill in the hours on the form if I wanted. This meant that the record would be dirty when I clicked the box and then I wouldn't be able to open and edit the same record in the VBA. I fixed that part but now I have a new problem. If I delete the format conditions for the boxes it deletes it for all of the records. It looks like I can't simply change the format condition. I have to delete it first, then add a new one. This means that each time I click a box I have to wait for VBA to loop through every box of every record and set new format conditions for each one. It takes way too long. I think I need a new approach unless anyone has any ideas.

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

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: 6/22/2026 11:10:15 AM. PLT: 0s