×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

click on any control triggers event

click on any control triggers event

click on any control triggers event

(OP)
I have many checkboxes on a form. If the user clicks on any one of them, I want to trigger an event (displaying a picture if the value is True). Is there a way to do this without having a procedure for each control?

Private Sub cbx1_Click()
End Sub

thru

Private Sub cbx30_Click()
End Sub

RE: click on any control triggers event

Can't exactly remember - but isn't there a KEYPRESS or MOUSE CLICK event that you can trap - possilby for the whole form??

Maybe this will trigger something for you..

RE: click on any control triggers event

In VB6-

The form has:
   MouseDown, MouseUp and Click

The Chkbox has:
   the same plus KeyDown, Keypress and Keyup

You should be able to trap on those

Good Luck

RE: click on any control triggers event

You probably need to iterate through the OLEObjects collection

CODE

For Each a In Me.OLEObjects
If Left(a.Name, 5) = "Check" Then
If a.Object.Value = True Then
MsgBox a.Name & " is checked"
End If
End If
Next

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376: Eng-Tips.com Forum Policies before posting
Steam Engine enthusiasts
Steam Engine Prints

RE: click on any control triggers event

If you are using VB6, you can create an control array and only have the code in one procedure.

RE: click on any control triggers event

This may be too late to help, but there is a way to create a single event procedure for multiple controls.  John Walkenbach explains how to do this on his "The Spreadsheet Page" website.  Here is the link to the specific topic page:  http://www.j-walk.com/ss/excel/tips/tip44.htm

The example code is set up for CommandButtons but you can change it to work with CheckBox controls.

Hope this helps.

Regards,
Mike

RE: click on any control triggers event

(OP)
Fantastic! That is exactly what I was looking for. I love it. Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources