Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    hi Steve, I copied the function Linq provided code for code. The error is on the last line of the module in post 11.

    I understand your point. Makes sense to me. I have many forms and they have different colours so to save meself the hassle of declaring umpteen variables (one for each form). I have declared a variable as Long and replaced the offending code with this:

    InactiveColor = CLng("&H" & strColor)



    I reckon should work

  2. #17
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    nah didn work

  3. #18
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    InactiveColor = CLng("&H" & strColor)
    This is wrong.

    The UDF (user defined function) Hexcolor() is no different that the functions IsNull(), Instr(), or Left(), except it is not built in.

    The code Linq posted in #11 takes the Access color number, removed the "#", changes the order of the color bytes (R,G,B), add the prefix "&H", then converts the number to a long.

    Usage:
    You must add the code to a module!
    Then, to set the background color, you can use:

    Code:
    Me.YourControlName.BackColor = HexColor("#B2A97A")
    or
    Code:
    Dim InactiveColor as Long
    
    InactiveColor= HexColor("#B2A97A")
    Me.YourControlName.BackColor = InactiveColor



    Another method is:
    Code:
    Dim InactiveColor as Long
    
    InactiveColor= RGB(178, 169, 122)    ' <= from the color picker
    Me.YourControlName.BackColor = InactiveColor

  4. #19
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    Exclamation option group

    Steve, I'm super now.

    1) I'd already added the code he gave me to a separate module. That is what you meant, right..?

    2) I already had this code "...Me.YourControlName.BackColor = HexColor("#B2A97A")..." in my AfterUpdate event.
    It is this code in the module that is giving me a belly ache: HexColor = CLng("&H" & strColor)

    I totally understand the logic of Hexcolor() being same as IsNull() but what should be the replacement code for that particular line? I shouldn't use same name for Funtion AND variable. So use another variable name? change the function name? change that code to HexColor(CLng("&H" & strColor))?


    2) It is the Label.Forecolor that I want to change not Backcolor though. Surely I don't have to touch the Back color as well?

  5. #20
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    Exclamation option group

    Steve, here's a stripped down copy of the database. Use sarah james/echo2 and it is the Paediatric form. Clicking "No" in the 1st option group should grey out the second group of controls. It appears to work until you click on "Yes" afterwards... The error message appears and wouldn't leave. Your help is greatly appreciated


  6. #21
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Post #20...... Uhhhhhh, dB not attached????


    Post @19:
    1) Yes

    2)
    It is this code in the module that is giving me a belly ache: HexColor = CLng("&H" & strColor)
    You don't do anything with this line. Forget about it.

    Functions return values, right? So this line is how you get the value to return. You have to set the name of the function to the value. The CLng part is changing the hex value to a Long Int (as a decimal). The "&H" indicates to Access that the number is hex.
    So you call the function using:

    Me.YourControlName.Forecolor = HexColor("#B2A97A")

    The code massages the argument so the color number becomes "7AA9B2", and the "&H" is added as a prefix. So now the color number is now "&H7AA9B2".
    The function CLng() converts the hex number to a decimal number, 8038834.
    The decimal number is set to the return return value statement as

    Hexcolor = CLng("&H" & strColor)

    which is

    Hexcolor = 8038834

    which is now the same as

    Me.YourControlName.Forecolor = 8038834


    2) or 3????
    Surely I don't have to touch the Back color as well
    No, you don't have to change the back color.

  7. #22
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    option group

    beautiful!! thank you Steve!! I had to read your explanation twice though. The first time had me reaching for a cup of coffee. After things calmed down, it made sense.

  8. #23
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    Exclamation option group

    uhh...yes, yesterday things were er a bit unsettled and I forgot to upload the database I understand the reason why I was getting the error is because I had "Text 1" as a colour in my code. I needed to replace this with the HEX equivalent which is #000000. The bug is gone now but database is attached for your viewing pleasure

    Your help has been invaluable . Thank you again.

    Attached Files Attached Files

  9. #24
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Thank you Linq for the code

  10. #25
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    the HEX equivalent which is #000000
    The decimal equivalent of hex #000000 is 0, so no need to call Hexcolor().
    Your code could be:
    Code:
       Me.Label1092.ForeColor = 0
       Me.Label1078.ForeColor = 0
       Me.Label1156.ForeColor = 0
       Me.Label1158.ForeColor = 0
       Me.Label920.ForeColor = 0
    Its faster.....


    Also, the check boxes Check1155 and Check1157 have the same control source.
    This is where taking the time to give meaningful names to controls pays off.

    The labels for the check boxes are "Unreactive pupil(s)" and "Cushing's reflex".

  11. #26
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    yes "0" will certainly make it faster. I have already gone full-steam-ahead but I'll file this for later use.

    you right AGAIN . I have over fifty controls on each form and naming them individually though time consuming, will clarify certain issues.

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

Similar Threads

  1. Option Group selection
    By mahmud1180 in forum Programming
    Replies: 4
    Last Post: 10-10-2014, 05:42 PM
  2. Replies: 4
    Last Post: 10-03-2014, 06:36 AM
  3. Option Group
    By x__hoE__x in forum Access
    Replies: 2
    Last Post: 12-10-2011, 09:39 AM
  4. Option Group
    By huskies in forum Forms
    Replies: 9
    Last Post: 12-02-2009, 12:06 PM
  5. Option Group broken out
    By dcecil in forum Reports
    Replies: 3
    Last Post: 04-21-2009, 10:30 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