473,772 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change the color of a button when clicked?

1 New Member
Hi I am new to the forum. I have created a form in Word 2007. I have implemented a radio button on the form. I want to add custom code so that every time the button is clicked, the color of the button changes. For example, I was thinking along the lines of a code that is similar to a snippet that I found on the web:

Expand|Select|Wrap|Line Numbers
  1. Private Sub OptionButton1_Click()
  2. Option Explicit
  3. Dim index As Integer
  4. Dim indicator(5) As ColorConstants
  5.  
  6. Private Sub Form_Load()
  7.   indicator(0) = vbGreen
  8.   indicator(1) = vbRed
  9.   indicator(2) = vbBlack
  10.   indicator(3) = vbYellow
  11.   indicator(4) = vbBlue
  12.  
  13. End Sub
Can you please provde guidance for me?
Thank you.
Vickie
Mar 2 '11 #1
4 8257
Guido Geurs
767 Recognized Expert Contributor
This is changing the color each time the optionbutton is clicked.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim indicator(5) As Variant
  3. Dim index As Integer
  4.  
  5.  
  6. Private Sub UserForm_Activate()
  7. indicator(0) = vbGreen
  8. indicator(1) = vbRed
  9. indicator(2) = vbBlack
  10. indicator(3) = vbYellow
  11. indicator(4) = vbBlue
  12. index = 0
  13. End Sub
  14.  
  15. Private Sub OptionButton1_Click()
  16.    OptionButton1.BackColor = indicator(index)
  17.    index = index + 1
  18.    If index > 5 Then index = 0
  19. End Sub
Mar 3 '11 #2
imavp2
7 New Member
Hi Guido.
Sorry for the delay. Thanks a million for the code and of course it worked. However, once I launched the form I realized it was not what I had in mind. I apologize. I have a form with several radio buttons. I was able to get the background to change colors for each button. I actually wanted the circle itself to change colors. Should I upload the form so you can better visualize what I am trying to accomplish? If you work with me on the code for this once, I am sure that I will catch on and not need to keep coming back. I have some VB6 code for circles that I can also share with you. Let me know if I need to upload both for your review.
Vickie
Mar 11 '11 #3
imavp2
7 New Member
Sorry. Ok I will remember to use tags for when uploading code.
Vickie
Mar 11 '11 #4
Guido Geurs
767 Recognized Expert Contributor
Please can you attach your code in Bytes?
You want to change the color of the button (the circle)it self?
Than it will not work with the standard radio buttons in VB6.
If so, we will have to create or own buttons!
Mar 11 '11 #5

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

Similar topics

4
3250
by: Jay | last post by:
I have a form used to submit data (no surprises there!). I'd like to be able to populate the same form with previously submitted data. The data lives in a database once submitted and using ASP I can populate text boxes/textareas using this data no problem. What about radio buttons? If I have 2 of them named the same rb1 and rb1 with values of yes/no respectively.
2
3493
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I can't get to make this combo work. <p>Did you have any problems finding any of the information...
1
6891
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
1
3231
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
10
6104
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
5
2725
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button are selected it should giv message dat select a radio button. else it should go to other page. My code works fine when there are more than 1 radio button but when only 1 radio button is der dat time it does not work
5
4155
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a MySQL database using JavaScript to find a product either by Product ID, Description, or Both. Originally, the 'Both' radio button was "checked" but I now want the 'Product ID' button set as the default choice (as you can see from the code below). ...
3
2850
by: jahphill | last post by:
Hey. I thought id make a seperate discusion because the other became a bit lengthy and confusing. Aim: Create a php file which works with the script below, which makes the radiobuttons work =D Right, when say mp3 radio button is selected, and say BLA is typed in the text box. I would like it to open up...
3
6196
johny10151981
by: johny10151981 | last post by:
Hi, Here a code part that create a group box and radio button hGroup=CreateWindowEx(0,L"BUTTON",L"Choose Connection type", WS_CHILD|WS_VISIBLE|BS_GROUPBOX|WS_GROUP,30,180,300,85,hWnd,(HMENU)10006,hInstance, NULL); CreateWindowEx(0,L"BUTTON",L"Direct Connection",WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON, 10,17,280,30,hGroup,(HMENU) 10010,hInstance ,NULL); CreateWindowEx(0,L"BUTTON",L"XML Connection",WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,...
7
4540
Fary4u
by: Fary4u | last post by:
how can i change radio button into image but functionality should be like radio button ? .pic { background:url(pic.jpg) no-repeat; } <input type=radio src=pic.jpg value=1 name=1> or <input type=radio class=pic value=1 name=1>
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.