I have a small form used for searching for names. There is a combo box on the form that lists the names from the underlying tables. In its default configuration, records with the yes/no field "CL_inactive" marked True are excluded. I have a check box on the form called "chkInactives" that will include the inactive people in the combo box drop down. I want the names of inactives ( if the user elects to show them) to be conditionally formatted with bold font but I am having no success. My code works to include or exclude inactives, but the only conditional fomratting I had any succcess with was to change ALL the names to bold font, not just the ones that are inactive.
My combobox is called CmboSearch. The conditional formatting formula I tried was [Cmbosearch]![Cl_inactive]=true . I also tried looping through the recordset of names and using the format conditions method but I am getting no where. Here is my code:
Code:
Private Sub ckInactives_AfterUpdate()On Error GoTo Err_ckInactives_AfterUpdate
Dim db As Database
Dim rs As Recordset
Dim strsql As String
Dim Frc As FormatCondition
strsql = "SELECT tblClients.ClID, tblPersons.Cl_ID, tblPersons.Cl_Lastname, tblPersons.Cl_FirstName, tblPersons.HeadHousehold, tblClients.Cl_inactive " & _
"FROM tblClients INNER JOIN tblPersons ON tblClients.ClID = tblPersons.Cl_ID ORDER BY tblPersons.Cl_Lastname;"
If Me.ChkInactives.Value = True Then
Me.CmboSearch.RowSource = strsql
Else:
strsql = "SELECT tblClients.ClID, tblPersons.Cl_ID, tblPersons.Cl_Lastname, tblPersons.Cl_FirstName, tblPersons.HeadHousehold, tblClients.Cl_inactive " & _
"FROM tblClients INNER JOIN tblPersons ON tblClients.ClID = tblPersons.Cl_ID WHERE (((tblClients.Cl_inactive)=False)) ORDER BY tblPersons.Cl_Lastname;"
Me.CmboSearch.RowSource = strsql
End If
strsql = ""
Exit_ckInactives_AfterUpdate:
Exit Sub
I did try adding this to the code above but kept getting a type mismatch error on the first line:
Code:
Set Frc = Me!CmboSearch.FormatConditions.Add(acExpression, , (Me!CmboSearch.Column(Cl_inactive) = True))
With Me!CmboSearch.FormatConditions(0)
.FontBold = True
.FontItalic = False
End With