473,394 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
Sep 14 '07 #1
13 3208
Scott Price
1,384 Expert 1GB
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
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
1,384 Expert 1GB
No problems! Glad it worked for you.

Regards,
Scott
Sep 14 '07 #4
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
1,384 Expert 1GB
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
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
1,384 Expert 1GB
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
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
1,384 Expert 1GB
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
1,384 Expert 1GB
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
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
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
1,384 Expert 1GB
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

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

Similar topics

3
by: Roberto Castro | last post by:
Hello! I have been assigned for the first time an adp Access project and so far I have managed to make the changes needed for some requirements. However, I am struggling to find the place where...
6
by: Jerry J | last post by:
Is there a way to change the background color of a web form on the server before it is posted? In the pageLoad event I can do it to server controls by adding an attribute, however, how do I do...
1
by: yxq | last post by:
There are two picturebox controls(A and B) on a form, the A's background color will become blue while clicks A(here, the B's background color will become control color), the B's background color...
0
by: =?Utf-8?B?UmljaA==?= | last post by:
I have a web browser control (VB2005) in a panel on a form. I use it only to open Reports from Reporting Services (sql Server 2000) or PDFs. So I am not using the web browser control for browsing...
8
by: Marco Pais | last post by:
Hi there. How can I change the background color of a textbox when it gets the focus? I can handle the "Enter" event and do this private void txtDummie_Enter(object sender, EventArgs e) { ...
9
by: mulchgirl | last post by:
I have my fields set up so that the background is white, but for some reason my combo boxes are white when the form is first opened, but as soon as you enter info into into them and tab away, the...
4
by: jitheshborgia | last post by:
i have changed my form's background color to transparent.Now the text boxes are not working.I have used the code below this.SetStyle(ControlStyles.SupportsTransparentBackColor,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.