Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53

    Why are colors changing in ListBox?

    Here is what I would like to have happen. I have a listbox that is for listing the quantity an item that is selected by the user. I want the up arrow to increase the quantity so I have to load the listbox in reverse order which I was able to do, but I want to start with a quantity of "1" so when I set the value after the listbox is loaded, the value is in inverted colors (i.e. forecolor is what, backcolor is black) and no matter what I do, I can't change that. So any ideas on solutions as I don't want the different colors. Here is the code:

    FindItemQtyIndex = 0

    lstbxManualEntryItemQty.RowSourceType = "Value List"

    Do



    DisplayFindItemQtyIndex = FindItemQtyTotal - FindItemQtyIndex

    FindItemQtyIndex = FindItemQtyIndex + 1

    FindItemQtyIndexAsString = DisplayFindItemQtyIndex

    If DisplayFindItemQtyIndex < 10 Then

    FindItemQtyIndexAsString = Chr(34) & Space(2) & FindItemQtyIndexAsString & Chr(34)

    End If

    lstbxManualEntryItemQty.AddItem (FindItemQtyIndexAsString)

    If FindItemQtyIndex = FindItemQtyTotal Then Exit Do

    Loop

    lstbxManualEntryItemQty.ForeColor = vbBlack
    lstbxManualEntryItemQty.BackColor = vbWhite
    lstbxManualEntryItemQty.Value = " 1"

  2. #2
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    How will you know which item is selected in the list?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What event is this code in?

    Please post code between CODE tags to retain indentation and readability.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53

    Code is in a KeyPress Down Event...

    Quote Originally Posted by June7 View Post
    What event is this code in?

    Please post code between CODE tags to retain indentation and readability.
    There is a whole bunch of code where the user is inputting a sku, but there are different formats for the SKU's, and the SKU length isn't always the same either. I hae all of that worked out, but once the code determines the SKU is valid, it searches for all the "records" that have that sku, with each record representing a quantity of one for that item. So I would like a listbox to contain all the numbers from 1 to the total number of those items that are in stock, and have each of those numbers listed in the list box. To complicate matters though, I want the UP arrow in the list box to increase the quantity of the item, which means the FIRST item added to the List box is the TOTAL number of items with that SKU in inventory. But once all the numbers are loaded, I want the listbox to display a quantity of " 1", and when I set the .value to " 1" The color for that number (and that number only) is with white forecolor and black backcolor.

    As requested here is the code again, I hope I doing the TAGS correctly:

    Code:
         FindItemQtyIndex = 0
                    
         lstbxManualEntryItemQty.RowSourceType = "Value List"
                    
         Do
                        
               DisplayFindItemQtyIndex = FindItemQtyTotal - FindItemQtyIndex
                        
               FindItemQtyIndex = FindItemQtyIndex + 1
                        
               FindItemQtyIndexAsString = DisplayFindItemQtyIndex
                        
               If DisplayFindItemQtyIndex < 10 Then
                        
                     FindItemQtyIndexAsString = Chr(34) & Space(2) & FindItemQtyIndexAsString & Chr(34)
                            
               End If
                        
               lstbxManualEntryItemQty.AddItem (FindItemQtyIndexAsString)
                                           
               If FindItemQtyIndex = FindItemQtyTotal Then Exit Do
                        
       Loop
                    
       lstbxManualEntryItemQty.ForeColor = vbBlack
       lstbxManualEntryItemQty.BackColor = vbWhite
       lstbxManualEntryItemQty.Value = "  1"

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Does it look like they are correct?

    Take out the / from the first Code tag.
    Or use the # button to get them created correctly.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  7. #7
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    Quote Originally Posted by orange View Post
    Can you post a copy of the database or a subset showing the issue and related code?
    The issue is not with the database. I can create a generic list box with a list of numbers and the same problem occurs. The issue is when I set the listbox.value to " 1" using VBA code, the " 1" is displayed with a fore color of white and back color of black, and it cannot be changed. If I loaded the listbox normally, this would not be a problem since the first item added is what is displayed, but because I have to load it in reverse order so the UP ARROW on the list box increases the quantity the list box displays the highest number loaded, which I do not want.

    Thanks

    Ken L

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I for one, do not understand what you are describing. Picture worth a thousand words which is why we suggest providing db so we can see what you see.

    Or build some kind of mockup visuals and post those.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    The colour is to show what is selected?
    If you have multi select others will be that colour as well.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by kleaverjr View Post
    I can create a generic list box with a list of numbers and the same problem occurs.
    But we can't do the same because, for example, we have no data table, and no code for what I assume are functions FindItemQtyTotal and FindItemQtyIndex.
    You have your complete database and we have a few lines of code. Then you expect us to know more about the problem than you do. In this case, it can't work that way. If you refuse to provide requested data I don't see how I can help.

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Try deselecting the listbox entry
    http://allenbrowne.com/func-12.html

    Everyone else, I believe the OP is talking about the last entry being selected as he has set it to go to the bottom of the list.

    I am trying to think of the name of a control where you increment/decrement the value by using the arrows on the side of the control.

    Thought of it, spinner control.
    https://www.fmsinc.com/microsoftacce...ton/index.html
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    This set of code does the same thing without needing anything from the database. So you should be able to run it for yourself after you create a form and the lstbxmanualentryItemqty listbox.

    The reason for not including the DB is because there are over 30 pages of printed code just on this form, to get to the point where it searches for how many of these items are in stock because I want to track how long each specific physical item in inventory takes to sell, each item is it's own record in the inventory table. Not the most efficient way to record the info, but there are other reasons too for doing this. And there are several variables involved that are Global that are set for the entire program, and a module that retrieves the data as there are other forms that need to retrieve inventory data. So try to keep it brief, sharing the DB would do little good at this point for this issue, since the issue is only with the ListBox and how it is displaying the numbers and not where the numbers (or in this case the one number that determines the maximum number that can be selected by the user) .

    Thanks all

    Ken L

    Code:
    Dim FindItemQtyTotal As Long
    dim Find ItemQtyIndex as long
    dim  FindItemQtyIndexAsString  as string
    dim DisplayFindItemQtyIndex as long                     
    
    
    
    
                    FindItemQtyTotal = 66
                    
                    FindItemQtyIndex = 0
                    
                    lstbxManualEntryItemQty.RowSourceType = "Value List"
                    
                    Do
                        
                        DisplayFindItemQtyIndex = FindItemQtyTotal - FindItemQtyIndex
                        
                        FindItemQtyIndex = FindItemQtyIndex + 1
                        
                        FindItemQtyIndexAsString = DisplayFindItemQtyIndex
                        
                        If DisplayFindItemQtyIndex < 10 Then
                        
                            FindItemQtyIndexAsString = Chr(34) & Space(2) & FindItemQtyIndexAsString & Chr(34)
                            
                        End If
                        
                        lstbxManualEntryItemQty.AddItem (FindItemQtyIndexAsString)
                                           
                        If FindItemQtyIndex = FindItemQtyTotal Then Exit Do
                        
                    Loop

  13. #13
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    This is what is showing which I do not want when I set the list box value to something after the listbox is created:

    Click image for larger version. 

Name:	REGISTER-REVERSED COLORS.png 
Views:	18 
Size:	171.5 KB 
ID:	50562

    The listbox is circled in red.

    This is what I want the colors to look like no matter which qty is selected, also circled in red

    Click image for larger version. 

Name:	REGISTER-CORRECT COLORS.png 
Views:	18 
Size:	182.8 KB 
ID:	50563

    Thanks all!

    Ken L

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    @kleaverjr,
    You are trying to create a spinner control, when access already has one in your version I believe?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Listboxes are intended to show a list and highlight the selected row so the user knows which row is selected. It is just the way they work and there is nothing you can do about it. Change to a combo or spinner control as WGM suggests

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

Similar Threads

  1. Theme, colors
    By lefty2cox in forum Access
    Replies: 1
    Last Post: 03-07-2021, 09:08 AM
  2. Replies: 8
    Last Post: 02-07-2021, 05:29 AM
  3. Replies: 4
    Last Post: 05-30-2016, 10:53 AM
  4. Replies: 12
    Last Post: 01-08-2014, 05:15 PM
  5. Globally changing colors on forms
    By pwdpwd in forum Programming
    Replies: 2
    Last Post: 11-23-2010, 09:06 PM

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