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 / August 2006

Tip: Looking for answers? Try searching our database.

is there a with command buttons

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rodchar - 08 Aug 2006 04:19 GMT
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
Allen Browne - 08 Aug 2006 04:36 GMT
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
 
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.