Write a function that accepts an argument indicating which button called it,
and use a Select Case construct in the function to do the processing.
For example the function could be like this
Function DoProcessing (strCmdButton As String)
Select Case strCmdButton
Case "Button1"
Debug.Print "Processing for button 1."
Case "Button2"
Debug.Print "Processing for button 2."
...
Case Else
Debug.Print "Oops. Forgot to handle " & strCmdButton
End Select
End Sub
And you call it by setting the On Click of Button2 to:
=DoProcessing("Button2")
If you don't want to pass the button name, and you are absolutely certain
the code will not be called by any other means that clicking the button, you
could drop the argument and use:
Select Case Form.ActiveControl.Name

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> is there any way to catch a button event in one procedure and based on
> which
> button was pressed (either by name or id property) do the processing.
>
> thanks
> rodchar
rodchar - 08 Aug 2006 13:57 GMT
Has Form.ActiveControl.Name in Access 2003 been deprecated because it's not
showing up in the code complete and when i try to run it i get an error
Private Sub DoProcessing()
Select Case Me.ActiveControl.Name
Case Me.Command0.Name
MsgBox "Command0 ran"
Case Me.Command1.Name
msgboox "Command1 ran"
End Select
End Sub
> Write a function that accepts an argument indicating which button called it,
> and use a Select Case construct in the function to do the processing.
[quoted text clipped - 26 lines]
> > thanks
> > rodchar
Allen Browne - 08 Aug 2006 16:04 GMT
Still works here.
The specific properties may not show up in the Intellisense, because its a
rather generic object, but it still works without error.

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Has Form.ActiveControl.Name in Access 2003 been deprecated because it's
> not
> showing up in the code complete and when i try to run it i get an error