Results 1 to 5 of 5
  1. #1
    TOPSie is online now Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    116

    Colo(u)r - what is the return value of the RGB Function?

    In any new code I develop I use the RGB function when defining control backcolor. But I have come across some old code which I am trying to tweak which just uses a Long value for colour definition.



    The problem is it seems back to front and inconsistent.

    In a table of "colour correspondence" a value of "A" has a colour value (long) of 255 - (which if I was starting from scratch I would use RGB(255,0,0).

    If the control has a value of "A" this value (255) when assigned control.backcolor = 255 renders the control RED in some cases - but in others it appears as GREEN (RGB(0,255,0)

    Both cases of the code use the same lookup to find "A" = 255 and make similar backcolor assignment. So I am very confused

    Can anyome explain the return value of the RGB function because it isn't a simple conversion of FF0000 which would be 16711680 (if I put this value in my lookup table it makes BLUE

  2. #2
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,656
    rgb function returns a long
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,427
    Can anyome explain the return value of the RGB function because it isn't a simple conversion of FF0000 which would be 16711680 (if I put this value in my lookup table it makes BLUE
    No, I don't think anyone can explain the logic behind color representation consistency. The consistent element is inconsistency. Any claimed solution can be shot full of holes or is so convoluted as to be useless. When assigning colors, forget the numbers. Use a color picker to assign colors visually. To duplicate the chosen color, copy/paste the .backcolor property from one control to another. Good luck.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    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.

  5. #5
    TOPSie is online now Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    116
    OK.
    Somewhere in my original question I noted that one control was Green even though I was setting its Backcolor to Red. The issue here was that the control also had Conditional Formatting (to Green) so this obviously is actioned after the set Backcolor - So lesson here is to also check Conditional Formatting - which you have to dig down to find as it is not obvious from the Properties pane.

    So with that out of the way back to Colours in general.
    What seems to be happening here is that the RGB function should probably be called BGR.

    If you set a Colour to vbRed or RGB(255.0,0) then it is displayed as Red (as you would expect) - but if you look at what is actually returned by RGB it is 255 not 16711680. as you might have thought.

    So if you want to do your own colour scheme and you have got an RGB value from somewhere then before you pass the value to the vba RGB function you must swop over the R and B elements

    So FF0000 becomes 0000FF

    :-)

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

Similar Threads

  1. Function to return the highest value
    By harryklein in forum Access
    Replies: 6
    Last Post: 04-13-2021, 11:00 AM
  2. Replies: 10
    Last Post: 07-09-2019, 12:00 PM
  3. Find Function and Return Value
    By Whughes98 in forum Queries
    Replies: 5
    Last Post: 10-09-2018, 04:17 PM
  4. date function return value issue
    By live2ride in forum Access
    Replies: 3
    Last Post: 10-24-2012, 07:06 PM
  5. Function to return a set of records?
    By vicrauch in forum Access
    Replies: 2
    Last Post: 07-12-2011, 08:27 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