By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Form Event, Background color

P: 72
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
Sep 14 '07 #1
Share this Question
Share on Google+
13 Replies


Scott Price
Expert 100+
P: 1,384
Expand|Select|Wrap|Line Numbers
  1. Me.Detail.BackColor = vbRed
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
Sep 14 '07 #2

P: 72
Expand|Select|Wrap|Line Numbers
  1. Me.Detail.BackColor = vbRed
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
Sep 14 '07 #3

Scott Price
Expert 100+
P: 1,384
No problems! Glad it worked for you.

Regards,
Scott
Sep 14 '07 #4

P: 72
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
Sep 14 '07 #5

Scott Price
Expert 100+
P: 1,384
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
Sep 14 '07 #6

P: 72
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
Sep 16 '07 #7

Scott Price
Expert 100+
P: 1,384
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:
Expand|Select|Wrap|Line Numbers
  1. Me.Detail.BackColor = vbWhite
  2. Me!Frame2.Value = 2
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:
Expand|Select|Wrap|Line Numbers
  1. If Me!Frame2.Value = 1 Then
  2.     Me.Detail.BackColor = vbRed
  3. ElseIf Me!Frame2.Value = 2 Then
  4.     Me.Detail.BackColor = vbWhite
  5. End If
Regards,
Scott
Sep 16 '07 #8

P: 72
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:
Expand|Select|Wrap|Line Numbers
  1. Me.Detail.BackColor = vbWhite
  2. Me!Frame2.Value = 2
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:
Expand|Select|Wrap|Line Numbers
  1. If Me!Frame2.Value = 1 Then
  2.     Me.Detail.BackColor = vbRed
  3. ElseIf Me!Frame2.Value = 2 Then
  4.     Me.Detail.BackColor = vbWhite
  5. End If
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
Sep 17 '07 #9

Scott Price
Expert 100+
P: 1,384
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
Sep 17 '07 #10

Scott Price
Expert 100+
P: 1,384
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me!Check9.Value = -1 Then
  3.     Me.Detail.BackColor = vbRed
  4.     Me!Frame2.Value = 1
  5. ElseIf Me!Check9.Value = 0 Then
  6.     Me.Detail.BackColor = vbWhite
  7.     Me!Frame2.Value = 2
  8. End If
  9. End Sub
  10.  
  11. Private Sub Frame2_Click()
  12. If Me!Frame2.Value = 1 Then
  13.     Me.Detail.BackColor = vbRed
  14.     Me!Check9.Value = -1
  15. ElseIf Me!Frame2.Value = 2 Then
  16.     Me.Detail.BackColor = vbWhite
  17.     Me!Check9.Value = 0
  18. End If
  19. End Sub
Obviously if the individual controls are named differently in your database you'll need to change this code to reflect!

Regards,
Scott
Sep 17 '07 #11

P: 72
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
Sep 17 '07 #12

P: 72
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
Sep 17 '07 #13

Scott Price
Expert 100+
P: 1,384
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
Sep 17 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.