Results 1 to 11 of 11
  1. #1
    SteveApa is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    84

    Function to Change Color of Combo

    Hey.



    I have multiple Combo's on Multiple tabs on a form. I want to change the color of each of the combo's background based on selected value (After Update). I want to have 1 public function to change the color. If I call the public function from the AfterUpdate for each combo, how can I pass the specific info to the public function to know which combo to change??

    Code:
    Private Sub BusinessColor1Combo_AfterUpdate(What Do I pass???)
        Call Set_Commbo_Grade_Color
    End Sub
    Private Sub BusinessColor2Combo_AfterUpdate(What Do I pass???)
        Call Set_Commbo_Grade_Color
    End Sub
    
    
    
    Private Sub Set_Commbo_Grade_Color(?? How do I know which one to change color??? PassedCombo)
        Select Case PassedCombo
        Case "R", "r"
            PassedCombo.BackColor = RGB(255, 0, 0)
            PassedCombo.ForeColor = RGB(255, 255, 255)
        Case "Y", "y"
            PassedCombo.BackColor = RGB(255, 255, 0)
            PassedCombo.ForeColor = RGB(0, 0, 0)
        Case "G", "g"
            PassedCombo.BackColor = RGB(0, 100, 0)
            PassedCombo.ForeColor = RGB(0, 0, 0)
        Case "O", "o"
            PassedCombo.BackColor = RGB(255, 97, 3)
            PassedCombo.ForeColor = RGB(0, 0, 0)
        Case Else
            PassedCombo.BackColor = RGB(255, 255, 255)
            PassedCombo.ForeColor = RGB(0, 0, 0)
        End Select
    End Sub
    Thanks.
    Steve, Harrisburg, PA USA

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Would something like this work?
    Me!BusinessColor1Combo.BackColor=Set_Combo_Grade_C olor(Me!BusinessColor1Combo)

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    For starters, you have the "what do I pass" bit in the wrong place. It would after the function/sub name. That said, you may not need to pass anything. Look at using ActiveControl in the function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    First off, you most likely don't need to use this construct

    Case "R", "r"

    as Access is normally Case Insensitive, i.e. can't tell the difference between R and r or Y and y, etc.

    You can make Access Case Sensitive, but it takes some conscious effort, and is seldom done.

    Secondly, can you tell us, in non-technical, plain language, what these apparently identical Combobox are doing? To me, multiple Comboboxes, with identical selections, such as you've listed, shrieks of improper, possible non-normalized, design.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    SteveApa is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    84
    The combo boxes are Grading elements. There are many elements and a subjective grade. Each combo box is associated to a different element. I want, after the user selects a value, the combo box to change colors based on the value selected. There are 7x3 = 21 combo boxes. I want one function to be called to change the color, based on the combo's value, after the AfterClick event is fired off after each combo is updated.

    So, in each AfterClick event for each and every combo box, I want to call one function to change colors. How do I get the name of the control in the Afterclick event to pass to the public function to change the color of the proper combo?

  6. #6
    SteveApa is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    84
    Or... How do I get the full name of the AfterUpdate event sub name while I am in the sub - I could parse the function name to get the name of the control. If the after update event sub name is "BusinessColor1Combo_AfterUpdate", then I know the name of the control is "BusinessColor1Combo" that called it. I could find that combo from me.controls with the index and then set the color based on index that has a name that matches the control.

  7. #7
    SteveApa is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    84
    Found this on Stackoverflow.com. It returns the name of the current function you are in. Now I can know what the control name is (Parse off the "AfterUpdate")

    Application.VBE.ActiveCodePane.CodeModule.ProcOfLi ne(Application.VBE.ActiveCodePane.TopLine, 0)

    https://stackoverflow.com/questions/...t-vba-function

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by SteveApa View Post

    ...How do I get the full name of the AfterUpdate event sub name while I am in the sub...
    Is this what you mean:

    "Private Sub " & ActiveControl.Name & "_AfterUpdate()"

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    SteveApa is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    84
    The above does not work

  10. #10
    SteveApa is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Posts
    84
    Damn!!!! That is all I need! ActiveControl... I pass the active control!!! I Don't know why That took me so long.

    problem Solved!

    hey, how do I say "Solved"? for this thread


    Thanks.
    Steve

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You don't have to "pass" anything, just use ActiveControl in your function. You can mark the thread solved in Thread Tools at the top of the thread.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Change Text color and/or background color
    By Thompyt in forum Reports
    Replies: 2
    Last Post: 02-23-2017, 07:08 PM
  2. Change color
    By Lucas237 in forum Access
    Replies: 6
    Last Post: 07-30-2016, 04:01 PM
  3. change tab color or header color
    By witz07 in forum Access
    Replies: 6
    Last Post: 03-31-2016, 05:31 PM
  4. Replies: 8
    Last Post: 11-20-2013, 01:03 PM
  5. Change Change FormHeader Color
    By burrina in forum Forms
    Replies: 4
    Last Post: 12-19-2012, 08:18 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