Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Backcolor based on option group value (2007)

    I have an option group that can be either 1 (problematic) or 2 (reliable). When problematic is selected (value=1) I would like the backcolor of the option group (frame68) to be red. the code I wrote is not working. I have this as an after update event.

    Private Sub Frame68_AfterUpdate()
    If frame68="1" Then Frame68.BackColor = #ED1C24
    End Sub

    What am I missing? I get a compile syntax error.

  2. #2
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Backcolor based on option group value (2007)

    What format numerical value do I need if not Hex? The VBA helpfile indicates I can also use RGB. If I knew what the 12345 was, maybe I can find a conversion utility on line.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Backcolor based on option group value (2007)

    Edited by John to include the RGB function
    Even though Access 07 displays backcolor as a Hex Code, the value is a number, so VBA expects a numerical value.

    The RGB function converts an amount of red, green, blue to a color value.

    So try

    If me.frame68="1" Then
    me.Frame68.BackColor = RGB(255,0,0)
    else
    me.Frame68.BackColor = RGB(0,0,255)

    end if

    So also need some code in the on current event to set the colour for existing records.
    Regards
    John



  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Backcolor based on option group value (2007)

    I have just edited my previous post to use the RBG function.
    Regards
    John



  5. #5
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Backcolor based on option group value (2007)

    Thank you, I am much closer now. However, it does not seem to change to the correct color as I move from record to record. here is the code. It seemed to me that the code would be the same yet I wonder if I am using the wrong event. I know after update is correct but not sure about before update.
    ------------------------------------------------
    Private Sub Frame68_AfterUpdate()
    If Me.Frame68 = "1" Then
    Me.Frame68.BackColor = RGB(237, 28, 36)
    Else
    Me.Frame68.BackColor = RGB(214, 223, 236)
    End If
    End Sub
    --------------------------------------------------------------------
    Private Sub Frame68_BeforeUpdate(Cancel As Integer)
    If Me.Frame68 = "1" Then
    Me.Frame68.BackColor = RGB(237, 28, 36)
    Else
    Me.Frame68.BackColor = RGB(214, 223, 236)
    End If
    End Sub

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Backcolor based on option group value (2007)

    To deal with moving between records you need the same code as the after update event, but in the On Current event of the form.

    You don't use the before update event at all. The Before Update only fires when you update a field, but fires earlier than the after update event.
    Regards
    John



  7. #7
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Backcolor based on option group value (2007)

    Never mind - I was using the wrong event - I changed to on enter and all is good. thanks for the help.

  8. #8
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Backcolor based on option group value (2007)

    Me.Frame68 = "1" implies that the value is a string (which it isn't). Remove the quote marks around the 1.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  9. #9
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Backcolor based on option group value (2007)

    I spoke too soon. Now it is not working consistently. I did change "1" to 1 yet the backcolor only works correctly if I select (or reselect )the correct option. For example, if I close the DB then reopen, it does not work until I reselect that option. I am using 'after update' and 'on enter' events

    Okay - I figured it out. Again, the wrong event. I went to the on current event for the form instead of the 'on enter' event for the option group. Seems to work well now. Thanks again for the help/

  10. #10
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Backcolor based on option group value (2007)

    As John mentioned you should try the OnCurrent event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •