Solved

Checkboxes

Posted on 2002-03-20
3
219 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now