Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50

    Question How to grey out a list box


    Hello. I am trying to grey out a list box.
    Me.cmdButton.forecolor = RGB(160, 160, 160) works for a command button but does not seem to work for a list box.
    I would appreciate any help on how to do this

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Do you mean shade the fore-colour grey or back colour grey. Or do you mean disable it so it can't be clicked on?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    Hello. I meant to shade the fore-colour grey.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    It also works for a listbox
    Put the following code in Form_Load event
    Code:
    Me.Listbox.Forecolor=RGB(160,160,160)
    OR just assign a colour in the property sheet for the listbox using the colour selector
    It will be shown in HEX format e.g. #A5A5A5 or as a theme colour Background 1, Darker 25%
    You can't use RGB notation there
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    Thanks. I tried putting Me.Listbox.Forecolor=RGB(160,160,160) in my code but it doesn't change anything and I don't know why. I need to do this in code and not in the property sheet.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Correct - do it in code as I described - obviously use the correct name for your listbox!!!!
    OR use the property sheet as I described
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    Thanks again for replying. Yes I did exactly as written above but with the correct name for the listbox. I believe that this does method doesn't work with a list box. Have you tried it?
    I would appreciate if anyone could suggest a solution.

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Yes I've tried both methods and both work
    In fact you can do a lot more than that with listboxes
    This is an example of what is possible (though not necessarily desirable!)

    Click image for larger version. 

Name:	MutlicolourListbox.PNG 
Views:	28 
Size:	33.6 KB 
ID:	33238

    See https://www.access-programmers.co.uk...12&postcount=3 for more info and an example database
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    Thanks again for replying. I have tested this issue again in 2 separate databases.
    It seems that Me.Listbox.Forecolor=RGB(160,160,160) will not work for the 1st visible column in the listbox but does work for all other listbox columns.
    so I still believe there is a problem here.

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Not a problem for me - see attached
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    Thanks for sending the example db. I can see that you are right and that it is a problem in my db. I cant figure out what the problem is at the moment. Actually the listbox column header is greying out but not the values. If I get time I will try to replicate the problem in a sample db. Many thanks again.

  12. #12
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    Hello, I have a attached an example db that replicates my problem. When you click the top list box the after update property runs a query to populate the bottom list box. I include the line Me.lstWorkspaces.ForeColor = RGB(160, 160, 160) but you will see that only the header is greyed out. I would appreciate if you can shed light on this problem.
    Attached Files Attached Files

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Hi

    I can replicate your problem but i can't see what's causing it - I've tried changing the theme, creating a new form, decompiling & importing to a new database. None fixed it.
    I can only assume there is something obscure in your settings causing this but I can't see what it is

    What I can tell you is that you only need to set the row source for each listbox ONCE.
    As you've set both in the form design any additional code is pointless
    So everything in GREEN below should be removed

    Code:
    Option Compare Database
    Option Explicit  '<== ALWAYS ADD THIS 
    
    'Private Sub Form_Open(Cancel As Integer)
        'Me.lstReports.RowSource = "qryReports"
        'Me.lstReports.RowSourceType = "Table/Query"
    'End Sub
    
    
    'Private Sub cmdPreview_Click()
        'Me.lstReports.RowSource = "qrySelectReports"
        'Me.lstReports.RowSourceType = "Table/Query"
    'End Sub
    
    
    Private Sub lstReports_AfterUpdate()
        'Me.lstWorkspaces.RowSource = "qryReportWorkspace"
        'Me.lstWorkspaces.RowSourceType = "Table/Query"
       ' Me.lstWorkspaces.ForeColor = RGB(160, 160, 160)  'NOT NEEDED IF SET IN FORM DESIGN
        
        Me.lstWorkspaces.Requery
    
    End Sub
    However that doesn't fix this issue
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  14. #14
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Aside from any other issue that was raised, you have set a format on the table field. Try removing it.
    Don't understand why you'd have such a format when there's only one placeholder.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Well spotted. Removing the @ format fixes the first listbox
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Options going grey
    By Always_Learning in forum Forms
    Replies: 4
    Last Post: 04-28-2016, 09:59 AM
  2. How to grey out controls
    By Emma35 in forum Forms
    Replies: 5
    Last Post: 01-28-2014, 11:17 AM
  3. .MDE opens as grey box..
    By redbull in forum Access
    Replies: 1
    Last Post: 06-04-2013, 07:55 AM
  4. Replies: 4
    Last Post: 06-16-2011, 09:30 PM
  5. Toolbox grey
    By Jas_The_Ace in forum Forms
    Replies: 1
    Last Post: 02-27-2009, 08:20 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