Button names in VB


Posted by Charles Parsons on April 23, 2001 6:16 AM

I have an opening page with twenty active buttons, most of which began life as a picture or a group. Currently, each button is assigned its own macro. I would like to replace the 20 macros with one macro (assigned to all 20 buttons) that does something based on which button was selected, along the lines of
IF("Button1", do something)
IF("Button2", do something else)
(Obviously, a judicious renaming of buttons will help.) The problem is, apparently once a macro is assigned to an object to form an active clickable button, VB no longer utilizes the object's name, it only recognizes the underlying macro. Is this true?

Posted by Dave Hawley on April 24, 2001 1:44 AM


Hi Charles

You can handle this like this:

Assign ALL your buttons to this macro:

Sub MyMacro()
Run "DoItAll"
End Sub


Then within the same Sub put some code like this:

Sub DoItAll()
SCameFrom = Application.Caller
Select Case SCameFrom
Case "Button 1"
'Do this
Case "Button 2"
'Do that
Case "Button 3"
'Do something
Case "Button 4"
'Do another thing
Case "Button 5"
'Do another thing altogether
End Select

End Sub


This will determin which button was clicked. to find out the return Value from a Button, shape or whatever just use a msgbox in your "doItAll" procedure. eg;

SCameFrom = Application.Caller
msgbox SCameFrom

Dave

OzGrid Business Applications



Posted by CP on April 25, 2001 6:34 AM

Thank you, Dave. Like a charm.

So naturally I go to online help to check out this magic caller function. Sigh. Now I'm beginning to understand the booming popularity of message forums.