is there a with command buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

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
 
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
 
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
 
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.
 
Back
Top