Results 1 to 6 of 6
  1. #1
    dgmdvm is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2014
    Posts
    84

    Conditional Formatting in combo box

    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

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Sorry, but can't be done, see here more info:https://social.msdn.microsoft.com/Fo...orum=accessdev

    Cheers,
    Vlad

  3. #3
    dgmdvm is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2014
    Posts
    84
    well, that's disappointing but at least now I can stop beating my head against the wall trying to figure this out! Thanks for the link, too. I will play around with the subform option.

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    I recall (I think) a similar issue where responses were not encouraging and the answer was Rich Text. Not to say that this is the case here as it didn't involve a combo box, but I think it was a list box. It might be worth exploring and I might still have the example because I came up with the solution. I will check if you're interested, but it would be simpler to include a field in the combo to denote values that belong to a group.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    You CAN have some limited colour formatting in combo boxes but what you can do depends on the field datatype.
    For text, the options are to colour null and not null differently.
    Have a look at this thread and see if it can help for your situation https://www.access-programmers.co.uk/forums/showthread.php?t=297923
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    dgmdvm is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2014
    Posts
    84
    Quote Originally Posted by Micron View Post
    but it would be simpler to include a field in the combo to denote values that belong to a group.
    I did this but didn't like the looks of it so I opted just to leave the form the way it is. Thanks anyway.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-12-2015, 10:46 AM
  2. Replies: 5
    Last Post: 09-16-2015, 10:32 PM
  3. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  4. Replies: 2
    Last Post: 01-21-2013, 10:38 PM
  5. Conditional Formatting
    By riaarora in forum Access
    Replies: 6
    Last Post: 09-03-2012, 05:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums