After Update event fails to change list box font color (1 Viewer)

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
I have a list of reports on a form (in a list box). When the user selects an item in this listbox, after update event code on the list of reports enables or disables four other list boxes on the form. This same code chunk changes the font in a disabled list box to be grey. Well - it is supposed to do that, and indeed does work for 3 listboxes on the form, but not one of them.

The code for each list box is exactly the same. They are all simple multi-select list boxes. I have compared every property on each list box to make sure they are all identical. (I've even tried removing the problem list box, recreating it from scratch in case something was buried that I can't see.)

I have stepped through the code - nothing is remiss. But the list box font stays black. (The only solution I can come up with is to do something like hide the ones that don't apply, but I hate to do that.) The commented out message code tells me the font color IS now grey - but that's not what the screen shows!

Any thoughts are appreciated! Thanks in advance.

Code:
If Me.lstReports.Column(12) = True Then
    Me.calcContactTypeCount = Me.lstContactTypes.ItemsSelected.Count
    Me.lstContactTypes.ForeColor = RGB(0, 0, 0)
    Me.lstContactTypes.Enabled = True
Else
    Call ClearSelList(lstContactTypes)
    Me.calcContactTypeCount = 0
    Me.unbContactTypes = Null
    'this is the list box where this forecolor does not change from black to grey
    'yet the msgbox indicates it is now grey (it lies)
    Me.lstContactTypes.ForeColor = RGB(211, 211, 211)
    Me.lstContactTypes.Enabled = False
    'msgbox "The contact type box forecolor is " & Me.lstcontactTypes.Forecolor
End If
 

Minty

AWF VIP
Local time
Today, 06:21
Joined
Jul 26, 2013
Messages
10,371
Disabling the control will turn it grey, regardless of the colour you set.
However, you won't be able to disable it if it has the focus?
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
Yes - I'm being picky - the visual "grey" isn't super obvious to the user that the list box is no longer active. I wanted it to stand out after they pick a report when one of the filter option list boxes doesn't apply. The control doesn't have the focus - but I also just discovered something else which is even weirder, indicating it's not the code that is an issue. I decided to just skip changing the font color, but also changing the default forecolor on ALL list boxes to be a dark grey. The problem list box still has a black font! The bottom line is that my list box isn't paying any attention to the default color assigned to it! Sorry to not have checked this out before posting - never thought to check something more fundamental first :unsure:
 

Minty

AWF VIP
Local time
Today, 06:21
Joined
Jul 26, 2013
Messages
10,371
Possibly a corrupt list box control on the form? Or check you are referring to the correct object?
Take a backup of your whole database.

Delete the control.
Save the form.
Compact and repair the database.
Recreate the list box.
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
Yes - good suggestion for something I have seen in the past. I already did that, but will try a total decompile with the decompile command.
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
So weird. That didn't work either. The fear of course is that there is some sort of corruption somewhere - but I deleted the list box, then did a compact and repair. Then did a command box full decompile (/decompile switch). Then compacted and repaired. Then recreated the list box, did another compact and repair. No go. When I change the font color - in design view the new font color selected shows up - but as soon as I go into form view, the font reverts back to red. There is no code on the opening of the form that could possibly impact it (but just to be totally sure I also tried commenting out what I was doing on open - a maximize of the form, and hiding a menu form.)

SO - I'm totally stumped, and have decided that the "solution" is to just stick with the black font and accept the slight greyness of a disabled control. It is one of those things that just makes no sense though. Thanks Minty.
 

Minty

AWF VIP
Local time
Today, 06:21
Joined
Jul 26, 2013
Messages
10,371
That's weird. Try calling it a slightly different name, just for stuff and giggles?
 

bastanu

AWF VIP
Local time
Yesterday, 22:21
Joined
Apr 13, 2010
Messages
1,402
Can you please try to add Me.Repaint after the If statement block, I have tested this on a sample I have and it disables the list box and also changes the forecolor to red:
Code:
If Me.chkExecuteMK = True Then
    Me.List225.ForeColor = RGB(0, 0, 0)
    Me.List225.Enabled = True
Else
    
    'this is the list box where this forecolor does not change from black to grey
    'yet the msgbox indicates it is now grey (it lies)
    Me.List225.ForeColor = RGB(255, 0, 0)
    Me.List225.Enabled = False
    'msgbox "The contact type box forecolor is " & Me.lstcontactTypes.Forecolor
End If
Me.Repaint

Cheers,
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
Minty - a new name didn't change anything. I did laugh though - because over lunch I was explaining this to my husband, and said the ONLY thing I can possibly think is that lstContactTypes has some internal meaning to access.... but lstIndivContTypes as a new name didn't help. :( I'm done - am going to chalk this up to things that go bump in the night and hope I never see it again. For bastanu, the repaint doesn't do it - turns out it's not a code thing at all - this actually belongs in the regular form design forum once I discovered that just changing the property on the control doesn't even work! Thanks for the quick responses. Will be interested in hearing whether anyone else has ever run across this - but at this point it's just for the sake of satisfying curiosity. Li'l sigh here!
 

bastanu

AWF VIP
Local time
Yesterday, 22:21
Joined
Apr 13, 2010
Messages
1,402
Hi Cindy,

Here is a sample doing what I believe you want. So if it doesn't work for I would suggest you redo the entire form from scratch (in post #6 you said you removed it then decompiled\compacted then added it back to the same form). I normally just start with a blank new form in design view, copy and paste all the controls section by section (header, detail then footer), then copy the entire code module, save new form with new name, delete old form, compact then rename new form as old form and finally compile the code....

Cheers,
Vlad
 

Attachments

  • SampleListBox.accdb
    432 KB · Views: 223

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
Just did that. Still have same issue. Thanks for the suggestion, I had hope it would work. :unsure:
 

bastanu

AWF VIP
Local time
Yesterday, 22:21
Joined
Apr 13, 2010
Messages
1,402
Weird...What happens if you comment out the line with Call ClearSelList(lstContactTypes)? Have you put a break in the code and step through?
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
Vlad - you missed part of the thread. I originally reported this as a coding issue, but it turns out it has nothing to do with the code. As a matter of fact, with all code STRIPPED from the form (recreated), the problem is still there. Picture a form that has a handful of list boxes on it, and the forecolor property for all of the boxes has been set the same. I could set them all to be a light grey font. I used standard colors - no themes. All listboxes except for my "problem" one will then have a grey font. The problem list box, however, is black. A problem totally non-related to any coding. (And yes, for what it's worth - before discovering that, I stepped through the code and even the locals window showed that the forecolor was grey - but as soon as the form was opened in form view, the forecolor is black. I even put code on the form that popped up a message stating what the color of the list box is, and it told me it was the light grey that I wanted - but clearly, the font was black. ) I'm giving up on this one - I've been doing access design for over 20 years, never saw anything quite like this - have decided to just move on and not spend any more time trying to fix it given that all the obvious possibilities have been exhausted! Thanks for the effort.
 

bastanu

AWF VIP
Local time
Yesterday, 22:21
Joined
Apr 13, 2010
Messages
1,402
I've been doing Access development since Access 2.0 and I can say that I saw lots of quirks and weird things but in the end was able to solve them one way or another.... In your case seems like form corruption, the last thing you could try is to import all objects but that form into a new Access file then rebuild the form in that brand new file in case there is some weird corruption in the system tables. And yet another is to try to use SaveAsText and LoadFromText on that form (https://access.uservoice.com/forums...ument-the-loadfromtext-and-saveastext-methods).

Good luck!
Vlad
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
Sounded like it would be worth a try - but even with a totally new database, the issue remains. However, I copied and pasted the form objects - and maybe just maybe it will be better to not use anything from the old form - to actually build the problem form totally from scratch? I'm going to import all objects again in a new file, excluding the problem form. And then try just putting the one list box on it that is giving me grief.
 
Last edited:

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
oh wow. New database. Did not bring in problem form. Created a new form and only put ONE list box on it, which is using the same Row Source. There are only two fields in the source. I changed the forecolor to red just for giggles. Then when I go to form view, the primary key appears in red, and the second field is black. I don't want to display the primary key - so when I change the column widths to hide it, sure enough, I get a black font on this list box. The underlying table is a tiny thing - (22 records) - an autonumber primary key, one string field, and a few boolean fields. I'm only pulling in the primary key and the string into the list box. This is getting even crazier, huh? Thoughts?
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
I created another database that has nothing other than the underlying table and one form with a list box that is using that table (lt_categories). Problem persists. The table is a linked table. I opened the linked table - saved it in design view to a local table, and pasted the same records into it. Repointed the list box to the new local table, and the problem goes away. SO... thinking this has something to do with the table it is linked to, I refreshed all table links in my original database. Problem persists. I deleted the lt_categories linked table and manually relinked to that one table. Problem persists. I then created a new BACK END database - imported all back end tables into that, and relinked my original front end file to the new back end - problem persists. Any other thoughts? Now this one is going to keep me up at night lol....
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:21
Joined
May 7, 2009
Messages
19,230
do you still experience the same on this one?
 

Attachments

  • listboxForecolor.accdb
    576 KB · Views: 229

bastanu

AWF VIP
Local time
Yesterday, 22:21
Joined
Apr 13, 2010
Messages
1,402
Cindy,
Any chance you could create a sample db with just the form in question and a sample back-end with just dummy records to feed that form? This gets challenging ....yum...!
Cheers,
Vlad
 

CindyKredo

New member
Local time
Yesterday, 22:21
Joined
Nov 8, 2019
Messages
19
OMG Vlad - found the cause. The string field on the linked table had a format property of @. I don't recall ever setting that - as a general rule I do all formatting at the form level. When I saved the linked table as a local table, it stripped the format property - hence the local table was working, nothing to do with it being local vs. linked. Thanks so much for your time and suggestions - (to Minty and 'arnelgp' too!) - accepting the challenge when I was giving up. Good life lesson, right? (I don't even know what that symbol is supposed to do... but have seen it in the past - it sounds like it's time for me to figure that one out.)
 

Users who are viewing this thread

Top Bottom