Solved

Checkboxes

Posted on 2002-03-20
3
225 Views
Last Modified: 2010-05-02
How do i set up a script when userform2 checkbox 10 or 11, or 12, or 6 is checked then userform 5 label 28 background color will turn yellow, else the background color will stay the same
0
Comment
Question by:stormhunter2000
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
mdougan earned 21 total points
ID: 6882700
It's not clear what environment your in.  If it's VB, what are the names of the checkboxes?  Are the part of a control array?  Same question for the Labels?

Assuming that your checkboxes are all named chkBox and they have indexes (so, they're in a control array), and your labels are also in a control array with a name lblLabel, and the language we're coding in is VB or VBA then the code would look like this:

if userform2.chkBox(6).value = 1
or userform2.chkBox(10).value = 1
or userform2.chkBox(11).value = 1
or userform2.chkBox(12).value = 1 Then
   userform5.lblLabel(28).backcolor = vbYellow
End if

It's possible that the checkbox uses True or False, if so, then change the .value = 1 to .value = True

If you're not in VB and vbYellow is not a constant that is available, you can probaby use RGB(255,255,0)
0
 
LVL 1

Expert Comment

by:CodeWizrd
ID: 6883434

If userform2 is not modifiable when userform5 is displayed, then mdougan's example will work in the form_load() of userform5.  This may just be personal preference, but I always use a bang (!) between form and control names (userform2!chkbox(6).value for example).

If, however, the user is able to 'click' the checkboxes while userform5 is already loaded, I would create a sub to handle the updating of the backcolor (pseudocode shown below).  Add a call to handle_backorder sub inside the _Validate for each checkbox (#'s 6, 10, 11, and 12) and the background color will change dynamically.

Pseudocode:
-----------

sub handle_backcolor()
 
   if userform2!chkBox(6).value = 1
      or userform2!chkBox(10).value = 1
      or userform2!chkBox(11).value = 1
      or userform2!chkBox(12).value = 1 Then
      userform5!lblLabel(28).backcolor = vbYellow
   else
      userform5!lblLabel(28).backcolor = vbGrey ' default
   end if

end sub

End if
0
 
LVL 1

Expert Comment

by:CodeWizrd
ID: 6883448
Ignore the last End If.  I dont know how it found it's way down there.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Protecting vb6 & .Net code Obfuscation 18 181
Excel Automation VBA 19 101
pop out of webbrowser1 control vba6 5 41
Powerpoint 2013: Change cell reference in excel link 3 119
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question