Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / January 2007

Tip: Looking for answers? Try searching our database.

Change button on click event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Snidow - 30 Jan 2007 20:05 GMT
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.
Allen Browne - 31 Jan 2007 06:00 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.