Solved

Newbie question:  How to group events all to do the same thing

Posted on 2003-11-20
3
189 Views
Last Modified: 2010-05-01
For example,

Private Sub optionButton1_MouseDown(ByVal Button As Integer, ...)
    myFunction1()
End Sub

Private Sub optionButton2_MouseDown(ByVal Button As Integer, ...)
    myFunction1()
End Sub

Private Sub optionButton3_MouseDown(ByVal Button As Integer, ...)
    myFunction1()
End Sub

1)  Is there a more efficient way of handling this for option buttons or other objects?  That is, Run myFunction1() when Event A, B, C... are found?

2)  If the answer to 1) is No, is there a more efficient way of handling this if the option buttons are using a group name or are contained within a frame?
0
Comment
Question by:wonda04
3 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 50 total points
ID: 9789712
make a control array (ie. name the option buttons all the same thing:

Private Sub optionButton_MouseDown(index as integer, ByVal Button As Integer...)
   msgbox "Option " & index & " clicked"
   myFunction1
end sub
0
 
LVL 8

Expert Comment

by:Rog
ID: 9789735
When you name each control the same name it is like an array.

The even shown above will fire when any control in that array is fired.  The index of which control was clicked is then passed into the function.

This can be very useful in dynamically creating controls on a form for instance.

Rog
0
 

Author Comment

by:wonda04
ID: 9789992
Hi bobbit32, Rog,

The index argument is not available with VBA. That is,...
 
    Private Sub optionButton1_MouseDown(ByVal Button As Integer, ...)

Any ideas?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now