Results 1 to 12 of 12
  1. #1
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65

    Change Form Background Colour

    Hi All i'm stuck again !
    I have a strange one this time....i'm using a Form whose background color is grey. On that Form there is an option group with two buttons on it. I've been asked to make the Form change it's background color depending on which option button is selected. So when neither button is pressed the Form background is grey....when Option 1 is selected it turns green and when Option 2 is selected it turns Red. Can this be done ?

    Thanks
    Em

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,528
    yes and no.
    no ,you cant have NO option. 1 button is always on.

    yes, you can change the background. The FRAME (box) that contains the buttons holds the value.
    each button must have a different value set....1,2,3

    so select the frame, property, events
    on the Afterupdate event, put this code

    Code:
     sub frame12_afterupate()
       select case frame12.value
          case 1
               me.background = vbGreen
          case 2
               me.background = vbRed
       end select
    end sub

  3. #3
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Code:
    Private Sub YourOptionGroup_AfterUpdate()
        Select Case YourOptionGroup.Value
            Case 1
                Me.Detail.BackColor = vbGreen
            Case 2
                Me.Detail.BackColor = vbRed
            Case Else
                Me.Detail.BackColor = RGB(192, 192, 192) 'I don't know code for grey ;)
        End Select
    End Sub
    Edit:
    Hah, posted at the same exact time as Ranman. But actually you can have option box with no value I think. if there's no default value set for it and form loads the option box has no value. If you call that AfterUpdate procedure on FormLoad it will change bkg colour to grey.
    Edit2:
    Just checked out of curiosity and you can also set option group value to null (not by clicking on option buttons but "from outside").
    Last edited by cyanidem; 01-22-2016 at 06:15 AM.

  4. #4
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    Thanks for the help again guys....i tried both suggestions but they're not working for me. Ranman i get an error message with the word 'background' highlighted in yellow and cyanidem nothing happens when i make a selection ?

  5. #5
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Can you show us the code you have?

  6. #6
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    This is what i currently have in the AfterUpdate event of the option group

    Code:
    Private Sub FrameSelect_AfterUpdate()
    Select Case FrameSelect.Value
          Case 1
               Me.Detail.BackColor = vbGreen
          Case 2
               Me.Detail.BackColor = vbRed
       End Select
    End Sub

  7. #7
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    That should work. Works for me anyway.
    Can you confirm your buttons return Option Value 1 and 2 respectively?
    If so, maybe you could upload your database? Stripped of confidential data of course.

  8. #8
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    Yes my option values are one and two. When i added the check boxes to the form i can't even see the checkmark when i check them ?
    Attached Files Attached Files

  9. #9
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    I don't know why but you're right, nothing worked in your test db straight after I opened it. I had to delete this option group and create a new one and it works with exactly same code, didn't even touch it... So maybe try this?

  10. #10
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    Ok just created a new option group and put the code back in to the AfterUpdate event and still nothing. I've checked the security settings and everything is ok. Would I need to change the names on the buttons in the group aswell ?

  11. #11
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,445
    The reason you are having a problem is the option group returns 1 or 2 whilst the field it is bound to is a yes/no field - change the options to 0 and -1 and modify the code and the form will change color

  12. #12
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    Ah yes that did it....well spotted sir. Thank you all again for your help

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

Similar Threads

  1. Replies: 3
    Last Post: 10-22-2015, 07:15 AM
  2. Background colour when Form centered
    By jcc285 in forum Forms
    Replies: 4
    Last Post: 03-13-2015, 12:43 PM
  3. Replies: 4
    Last Post: 10-28-2014, 09:51 AM
  4. subform background colour
    By gbmarlysis in forum Forms
    Replies: 1
    Last Post: 03-03-2012, 10:18 AM
  5. Change the colour of a form background
    By r_e_v_a_n_s in forum Forms
    Replies: 0
    Last Post: 11-15-2005, 03:39 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