klsblues
Member
- Local time
- Today, 22:02
- Joined
- Aug 2, 2023
- Messages
- 47
Hi all,
I am getting the error...
An error occurred: The format condition number you specified is greater then the number of format conditions.
I have a table that lists the status details of a job (see attached jpg) which allows the user to select (from a form) a fore color and back color for the format to be displayed on a txt field in a grid.
The first three formats work fine and any combination of back color and fore color displays as it should, but I get the error and no format displays on status 4 - 6. Here's the code, can anyone help with this please?
(For info, I call this on Form_Load)
Thanks in anticipation.
I am getting the error...
An error occurred: The format condition number you specified is greater then the number of format conditions.
I have a table that lists the status details of a job (see attached jpg) which allows the user to select (from a form) a fore color and back color for the format to be displayed on a txt field in a grid.
The first three formats work fine and any combination of back color and fore color displays as it should, but I get the error and no format displays on status 4 - 6. Here's the code, can anyone help with this please?
(For info, I call this on Form_Load)
Code:
Public Sub ApplyFormatConditions()
On Error GoTo ErrorHandler ' Add error handling
' Define recordset to hold formatting rules
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim BackColor As Long
Dim ForeColor As Long
Dim StatusID As Long
Dim StatusDescription As String
Dim JObStatus As Long
Dim i As Integer
' Set up the database and open the recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblStatus")
' Clear default formatting for JobStatusTxt
Me.JobStatusTxt.FormatConditions.Delete
' Loop through the recordset to apply each formatting rule
i = 1
While Not rs.EOF
' Retrieve formatting details from the recordset
StatusID = rs!StatusID
BackColor = rs!BackColor
ForeColor = rs!ForeColor
StatusDescription = rs!StatusDescription
JObStatus = Me.JObStatus
Debug.Print "BackColor: " & BackColor & ", ForeColor: " & ForeColor & ", Status: " & StatusID & ", Desc: " & StatusDescription
With Me.JobStatusTxt.FormatConditions.Add(acExpression, , "JObStatus = " & StatusID)
.BackColor = BackColor
.ForeColor = ForeColor
End With
' Move to the next record
rs.MoveNext
i = i + 1
Wend
' Close the recordset
rs.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
MsgBox "An error occurred: " & Err.Description
If Not rs Is Nothing Then rs.Close
End Sub
Thanks in anticipation.
Attachments
Last edited: