Conditional Formatting in a ListBox (Access :: VBA)

Hello Experts,
I am building a search form that will search for inactive/active records.  What I am trying to do is have the inactive records appear in grey and the active records to appear blue.  For each record, there is an attribute called blnActive that returns true/false values.
I am capable of determining the SQL, however, I need assistence with the VBA syntax.  Here is my pseudo code:

For i = 1 To rec Step 1
                item = rsP.Fields(0) & ";" & rsP.Fields(1)
                If rsP.Fields(2) = False Then
                    ' this line item should be 8421504
                    ' this line item should be 0
                End If
                Me.lstGrant.AddItem (item)
            Next i

Thank you for your quick response!

Who is Participating?
Arthur_WoodConnect With a Mentor Commented:
Individual lines in a standard ListBox cannot be formatted in any manner.  ALL lines will be of the same FONT, SIZE, BOLD/UNBOLD, COLOR...

Your only hope MIGHT be to use a Third Party listView control, but I cannot suggest any to look into, becuase Access only uses ActiveX (COM) controls, and with the introduction of .NET, no vendors are still selling COM/ActiveX controls for any purpose.

Rey Obrero (Capricorn1)Connect With a Mentor Commented:
you can not do this in a listbox. you can use a subform
see if this link helps
wendeenelsonAuthor Commented:
Thank you for your comment.  

I have had help with this problem before.  However, someone on EE deleted my question that was reserved in my Knowledge Base.  :- |  

In addition to VBA, I work with Component Toolbox (which is ActiveX).  Part of me doubts that is what I used before to solve this problem, but I will double check.

Thank you, once again!
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Rey Obrero (Capricorn1)Commented:
wendeenelsonAuthor Commented:
Is there a resource where I can retrieve the properties of ctList?  (i.e. the equivalent of "rowsource" and "additem" syntax terms.)

Thank you.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
dbi-tech rocks :-)

wendeenelsonAuthor Commented:
This is what I came up with for my code:
        If rs.RecordCount > 0 Then
            rsCt = rs.RecordCount
            For i = 0 To rsCt - 1 Step 1
                intFunderID = rs.Fields(0)
                txtName = rs.Fields(1)
                blnActive = rs.Fields(2)
                item = intFunderID & ";" & txtName & ";" & blnActive
                Me.ctList.AddItem (item)
            Next i
        End If

Where do I put the formatting code?  What is the syntax?

Thank you for your continued help.
wendeenelsonAuthor Commented:
I have decided not to use DBI-Tech's controllers afterall.  

I will accept the fact that I cannot change colors of the text.  Instead, I created a conditional statement:

IF blnActive = False then
   txtActive = "Inactive"
   txtActive = "Active"
end if

Then I am just displaying that in a column next to the Funder names.  Where I stand right now, this discussion is complete.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"I have decided not to use DBI-Tech's controllers afterall.  "

Just curious as to why not?

wendeenelsonAuthor Commented:
As far as I can tell, there is very little documentation for syntax out there.  I spent $400 on this software and the company wants to charge me more $$$ to get help developing with their product.  

Do you another resource for DBI-Tech Development Documentation?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Last I knew, all DBI controls come with a complete help file and sample mdb, certainly better documentation and example that M# has every produced.

wendeenelsonAuthor Commented:
They do, but it doesnot go far enough with explaining how the ListCargo works.- I am new to that arena
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.