Change button on click event

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

Guest

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

Allen Browne said:
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

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Greg Snidow said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top