Solved

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

Posted on 2003-11-20
3
191 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

803 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