Form Event, Background color

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wideasleep
    New Member
    • May 2007
    • 72

    Form Event, Background color

    Hello Everyone,

    I have a form that has a radio button called "damage" My employer wants the background of the form to turn a different color when this radio button is selected. Does anyone have the VB Code to make this happen?

    Thanks
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    #2
    [CODE=vb]Me.Detail.BackC olor = vbRed[/CODE]

    Is the general code to turn the background of the detail section to Red. The catch is that if using a form header/footer, etc, you will have to change each section's backcolor property individually.

    Regards,
    Scott

    Comment

    • wideasleep
      New Member
      • May 2007
      • 72

      #3
      Originally posted by Scott Price
      [CODE=vb]Me.Detail.BackC olor = vbRed[/CODE]

      Is the general code to turn the background of the detail section to Red. The catch is that if using a form header/footer, etc, you will have to change each section's backcolor property individually.

      Regards,
      Scott
      Scott,

      That worked great! I appreciate your reply.

      Thanks Again,

      Curt

      Comment

      • Scott Price
        Recognized Expert Top Contributor
        • Jul 2007
        • 1384

        #4
        No problems! Glad it worked for you.

        Regards,
        Scott

        Comment

        • wideasleep
          New Member
          • May 2007
          • 72

          #5
          Originally posted by Scott Price
          No problems! Glad it worked for you.

          Regards,
          Scott
          Scott,

          Whoa, I guess it worked too good. It turned all my records red on the form. I did have another selection with a radio button called, "Normal Wear" and I set that one to white. Any ideas? This is an option group by the way.

          Curt

          Comment

          • Scott Price
            Recognized Expert Top Contributor
            • Jul 2007
            • 1384

            #6
            Hmm... I'm unable to reproduce that problem in my test db... When I run the same code, it turns the background of the form to red, without affecting any text boxes/labels/etc on the form.

            When you say all the records turn red also, how are you displaying the records?

            Regards,
            Scott

            Comment

            • wideasleep
              New Member
              • May 2007
              • 72

              #7
              Originally posted by Scott Price
              Hmm... I'm unable to reproduce that problem in my test db... When I run the same code, it turns the background of the form to red, without affecting any text boxes/labels/etc on the form.

              When you say all the records turn red also, how are you displaying the records?

              Regards,
              Scott
              This is a combination of different fields on a form, but they all come from the same table. Text, Combo boxes and of course radio buttons. As I changed the selection to make the background turn red I went to the next record and that one was red too, and so were the rest. This is why I was wondering if the code needed to be put in for the option group instead of the actual radio button in the group.

              Curt

              Comment

              • Scott Price
                Recognized Expert Top Contributor
                • Jul 2007
                • 1384

                #8
                Originally posted by wideasleep
                This is a combination of different fields on a form, but they all come from the same table. Text, Combo boxes and of course radio buttons. As I changed the selection to make the background turn red I went to the next record and that one was red too, and so were the rest. This is why I was wondering if the code needed to be put in for the option group instead of the actual radio button in the group.

                Curt
                Ahh.. I begin to see what you are referring to!!

                You'll have to change the color back when you go to a new record... In your form's OnCurrent event you can put something like this:
                [CODE=vb]
                Me.Detail.BackC olor = vbWhite
                Me!Frame2.Value = 2[/CODE]

                This changes the color back to white on going to a new record, and resets your option group back to it's default value... (Obviously you'll need to rename the option group according to your db, and make sure that the 2 reflects the value for the radio button choice of white.)

                The code I'm using is under the option group's Click event:
                [CODE=vb]
                If Me!Frame2.Value = 1 Then
                Me.Detail.BackC olor = vbRed
                ElseIf Me!Frame2.Value = 2 Then
                Me.Detail.BackC olor = vbWhite
                End If[/CODE]

                Regards,
                Scott

                Comment

                • wideasleep
                  New Member
                  • May 2007
                  • 72

                  #9
                  Originally posted by Scott Price
                  Ahh.. I begin to see what you are referring to!!

                  You'll have to change the color back when you go to a new record... In your form's OnCurrent event you can put something like this:
                  [CODE=vb]
                  Me.Detail.BackC olor = vbWhite
                  Me!Frame2.Value = 2[/CODE]

                  This changes the color back to white on going to a new record, and resets your option group back to it's default value... (Obviously you'll need to rename the option group according to your db, and make sure that the 2 reflects the value for the radio button choice of white.)

                  The code I'm using is under the option group's Click event:
                  [CODE=vb]
                  If Me!Frame2.Value = 1 Then
                  Me.Detail.BackC olor = vbRed
                  ElseIf Me!Frame2.Value = 2 Then
                  Me.Detail.BackC olor = vbWhite
                  End If[/CODE]

                  Regards,
                  Scott
                  We're getting closer! I put in both codes and it worked with the exception of when I went back to records with the damaged radio button selected. It then put it back to the normal wear selection and turned it white again.

                  Curt

                  Comment

                  • Scott Price
                    Recognized Expert Top Contributor
                    • Jul 2007
                    • 1384

                    #10
                    Originally posted by wideasleep
                    We're getting closer! I put in both codes and it worked with the exception of when I went back to records with the damaged radio button selected. It then put it back to the normal wear selection and turned it white again.

                    Curt
                    Do you have a flag field in your table to indicate a damaged record? I think that's the simplest way to go about this part of it. A simple boolean yes/no field with a default of no should do the trick. Then we'll write the damaged records to yes on the click of the radio button, and we will have to add some checking into the On Current event of your form to let it know which color to be when going back to a damaged record!

                    Give me a minute to work on this, and i'll be back shortly with some more instructions.

                    Regards,
                    Scott

                    Comment

                    • Scott Price
                      Recognized Expert Top Contributor
                      • Jul 2007
                      • 1384

                      #11
                      After adding the yes/no field to indicate a damaged/undamaged record, you'll add a check box to your form bound to this field, make it invisible unless you really want to see it as another visual reminder of a damaged record.

                      This is the code I used in my test db to set the values, and read from them:
                      [CODE=vb]
                      Private Sub Form_Current()
                      If Me!Check9.Value = -1 Then
                      Me.Detail.BackC olor = vbRed
                      Me!Frame2.Value = 1
                      ElseIf Me!Check9.Value = 0 Then
                      Me.Detail.BackC olor = vbWhite
                      Me!Frame2.Value = 2
                      End If
                      End Sub

                      Private Sub Frame2_Click()
                      If Me!Frame2.Value = 1 Then
                      Me.Detail.BackC olor = vbRed
                      Me!Check9.Value = -1
                      ElseIf Me!Frame2.Value = 2 Then
                      Me.Detail.BackC olor = vbWhite
                      Me!Check9.Value = 0
                      End If
                      End Sub[/CODE]

                      Obviously if the individual controls are named differently in your database you'll need to change this code to reflect!

                      Regards,
                      Scott

                      Comment

                      • wideasleep
                        New Member
                        • May 2007
                        • 72

                        #12
                        I was just looking at the same thing. It seems the only way to go because there is no way to change the code to accomodate this. I'll give it a try and let you know how it works.

                        Thanks,

                        Curt

                        Comment

                        • wideasleep
                          New Member
                          • May 2007
                          • 72

                          #13
                          Scott,

                          I was looking at using just a checkbox but went ahead and used that code with a hidden checkbox and the radio button and that worked. Thanks for all the cooperation.

                          Curt

                          Comment

                          • Scott Price
                            Recognized Expert Top Contributor
                            • Jul 2007
                            • 1384

                            #14
                            Originally posted by wideasleep
                            Scott,

                            I was looking at using just a checkbox but went ahead and used that code with a hidden checkbox and the radio button and that worked. Thanks for all the cooperation.

                            Curt
                            Not a problem! Glad it worked for you...

                            Regards,
                            Scott

                            Comment

                            Working...