Greetings all. Is there a way to change the on click event of a command
button with the on click event of another command button? I am using Access
2003. Hypothetically, If I have cmd1, cmd2, cmd3 and cmd4 is there a way to
have the on click event of cmd1, cmd2, and cmd3 to be something like:
Private sub cmd1_click
on error....
some events
me.cmd4.onclick="some events"
exit...
err...
I need to be able to change the onclick event of cmd4 for a different event
depending on whether cmd1, cmd2, or cmd3 is clicked first. I would greatly
appreciate any help.
Set the button's On Click propert to the name of the function, not [Event
Procedure]. You can then assign it to a different function, e.g.:
Me.cmd4.OnClick = "=Function2()"
Of course you could approach the issue by adding a Select Case to the event
procedure, so it performed different operations under different conditions,
e.g.:
Private Sub cmd4_Click()
Select Case Me.cmd4.Caption
Case "Click Me to run function 1"
Call Function1()
Case "Click Me to run function 2"
Call Function2()
End Select
End Sub

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.
> Greetings all. Is there a way to change the on click event of a command
> button with the on click event of another command button? I am using
[quoted text clipped - 15 lines]
> greatly
> appreciate any help.
Greg Snidow - 31 Jan 2007 17:47 GMT
Allen, thank you so much for your input. I did not mention that I am using
ADP with SQL server, so I do not know if that would have affected your
advice, and I did not think it would have mattered until I saw your solution
involved having the command button call a function. I never thought to
include a select statement. What I did was to add an unbound text box to the
form and to update its value based on which button I clicked, just as an
option group works. I was then able to use the select case statement you
suggested. Thanks again.
> Set the button's On Click propert to the name of the function, not [Event
> Procedure]. You can then assign it to a different function, e.g.:
[quoted text clipped - 32 lines]
> > greatly
> > appreciate any help.