Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

click on any control triggers event

Status
Not open for further replies.

jrice174

Civil/Environmental
Nov 8, 2004
129
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
 
Replies continue below

Recommended for you

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..
 
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
 
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 before posting
Steam Engine enthusiasts
Steam Engine Prints
 
If you are using VB6, you can create an control array and only have the code in one procedure.
 
As this is the VBA forum - and VBA doesn't support control arrays - OP may need the workaround I suggested. I agree it would be easier IF it was VB6

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting
Steam Engine enthusiasts
Steam Engine Prints
 
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:
The example code is set up for CommandButtons but you can change it to work with CheckBox controls.

Hope this helps.

Regards,
Mike
 
Fantastic! That is exactly what I was looking for. I love it. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor