Command Button Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    Command Button Code

    I am calling an event from the on click event of a command button. I
    cant however figure out how to refrence "which" button was clicked in
    the first procedure, in the second procedure... In simplistic terms I
    would like the system to know which button was clicked on the parent
    form so that it can pull specific requirements within the other
    section of code... any help is greatly appreciated...
  • Allen Browne

    #2
    Re: Command Button Code

    You will need to pass this information to the procedure.

    For example:
    Private Sub Command3_Click( )
    Call DoSomething("Co mmand3")
    End Sub

    Function DoSomething(str WhoCalled As String)
    Debug.Print "Called by " & strWhoCalled
    End Function

    If you need to know which form it was a well, pass the button rather than
    its name. You can then examine its Parent.

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

    "Mike" <info@baltworld .comwrote in message
    news:7df893f9-321e-495c-9a6e-b9e42373eb36@k7 g2000hsd.google groups.com...
    >I am calling an event from the on click event of a command button. I
    cant however figure out how to refrence "which" button was clicked in
    the first procedure, in the second procedure... In simplistic terms I
    would like the system to know which button was clicked on the parent
    form so that it can pull specific requirements within the other
    section of code... any help is greatly appreciated...

    Comment

    • Mike

      #3
      Re: Command Button Code

      On Sep 19, 10:02 pm, "Allen Browne" <AllenBro...@Se eSig.Invalid>
      wrote:
      You will need to pass this information to the procedure.
      >
      For example:
          Private Sub Command3_Click( )
              Call DoSomething("Co mmand3")
          End Sub
      >
      Function DoSomething(str WhoCalled As String)
          Debug.Print "Called by " & strWhoCalled
      End Function
      >
      If you need to know which form it was a well, pass the button rather than
      its name. You can then examine its Parent.
      >
      --
      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.
      >
      "Mike" <i...@baltworld .comwrote in message
      >
      news:7df893f9-321e-495c-9a6e-b9e42373eb36@k7 g2000hsd.google groups.com...
      >
      >
      >
      I am calling an event from the on click event of a command button.  I
      cant however figure out how to refrence "which" button was clicked in
      the first procedure, in the second procedure...  In simplistic terms I
      would like the system to know which button was clicked on the parent
      form so that it can pull specific requirements within the other
      section of code... any help is greatly appreciated...- Hide quoted text-
      >
      - Show quoted text -
      Thanks.. I dont quite understand what your saying... here is the code
      behind the module... I simply want to be able to call this function
      instead of placing all of the code behind each button in each menu..
      am I thinking right??

      Public Sub Security_Menu()
      On Error GoTo Err_Menu_Securi ty_Click

      Dim MenuItem As String
      Dim UserName As String
      Dim dbuser As Variant
      Dim AuthUser As Variant
      Dim AuthTable As String
      Dim ActiveButton As String
      Dim ABSecurity As String

      ActiveButton = Form_frmEntryIn terface. '*****Heres where the
      problem is********

      AuthTable = "tbl_System_Use r_Menus"
      MenuItem = DLookup("Defaul tForm", "tblMenuOptions ", "CmdBtnName =
      " & "'" & ActiveButton & "'")
      ABSecurity = DLookup("CmdBtn Security", "tblMenuOptions ",
      "CmdBtnName = " & "'" & ActiveButton & "'")
      UserName = "UserName = " & "'" & CurrentUser() & "'" & "User_Menu
      = " & "'" & ABSecurity & "'"
      AuthUser = DLookup("[UserName]", AuthTable, UserName)
      dbuser = CurrentUser()

      If dbuser = AuthUser Then

      DoCmd.OpenForm MenuItem, , , , acFormAdd

      ElseIf IsNull(AuthUser ) Then
      MsgBox "Accessor with User Name " & [dbuser] & " is NOT
      authorized to perform the selected action. Please contact the system
      administrator for access.", vbCritical, "Not Authorized"
      End If

      Exit_Menu_Secur ity_Click:
      Exit Sub

      Err_Menu_Securi ty_Click:
      MsgBox Err.Description
      Call LogError(Err.Nu mber, Err.Description ,
      "Menu_Security_ Module", , False)
      Resume Exit_Menu_Secur ity_Click
      End Sub

      Comment

      • Volker Neurath

        #4
        Re: Command Button Code

        Mike wrote:
        I am calling an event from the on click event of a command button. I
        cant however figure out how to refrence "which" button was clicked in
        the first procedure, in the second procedure... In simplistic terms I
        would like the system to know which button was clicked on the parent
        form so that it can pull specific requirements within the other
        section of code... any help is greatly appreciated...
        In the parent form set a Variable for that Button and then open the child
        form and hand over this variable:

        strClickedButto n="command_2"

        DoCmd.OpenForm "MyChildForm",O penArgs:=strCli ckedButton

        [...]

        Volker
        --
        Im übrigen bin ich der Meinung, dass TCPA/TCG verhindert werden muss

        Wenn es vom Himmel Zitronen regnet, dann lerne, wie man Limonade macht

        Comment

        • Allen Browne

          #5
          Re: Command Button Code

          Change the first line of your code to:
          Public Function Security_Menu(A ctiveButton As String)

          Then in the On Click property for Button1, use:
          =Security_Menu( "Button1")
          and so on for your other buttons.

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

          "Mike" <info@baltworld .comwrote in message
          news:44c1ba92-56ae-4de7-8292-f07695412da2@b1 g2000hsg.google groups.com...
          On Sep 19, 10:02 pm, "Allen Browne" <AllenBro...@Se eSig.Invalid>
          wrote:
          You will need to pass this information to the procedure.
          >
          For example:
          Private Sub Command3_Click( )
          Call DoSomething("Co mmand3")
          End Sub
          >
          Function DoSomething(str WhoCalled As String)
          Debug.Print "Called by " & strWhoCalled
          End Function
          >
          If you need to know which form it was a well, pass the button rather than
          its name. You can then examine its Parent.
          >
          --
          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.
          >
          "Mike" <i...@baltworld .comwrote in message
          >
          news:7df893f9-321e-495c-9a6e-b9e42373eb36@k7 g2000hsd.google groups.com...
          >
          >
          >
          I am calling an event from the on click event of a command button. I
          cant however figure out how to refrence "which" button was clicked in
          the first procedure, in the second procedure... In simplistic terms I
          would like the system to know which button was clicked on the parent
          form so that it can pull specific requirements within the other
          section of code... any help is greatly appreciated...- Hide quoted
          text -
          >
          - Show quoted text -
          Thanks.. I dont quite understand what your saying... here is the code
          behind the module... I simply want to be able to call this function
          instead of placing all of the code behind each button in each menu..
          am I thinking right??

          Public Sub Security_Menu()
          On Error GoTo Err_Menu_Securi ty_Click

          Dim MenuItem As String
          Dim UserName As String
          Dim dbuser As Variant
          Dim AuthUser As Variant
          Dim AuthTable As String
          Dim ActiveButton As String
          Dim ABSecurity As String

          ActiveButton = Form_frmEntryIn terface. '*****Heres where the
          problem is********

          AuthTable = "tbl_System_Use r_Menus"
          MenuItem = DLookup("Defaul tForm", "tblMenuOptions ", "CmdBtnName =
          " & "'" & ActiveButton & "'")
          ABSecurity = DLookup("CmdBtn Security", "tblMenuOptions ",
          "CmdBtnName = " & "'" & ActiveButton & "'")
          UserName = "UserName = " & "'" & CurrentUser() & "'" & "User_Menu
          = " & "'" & ABSecurity & "'"
          AuthUser = DLookup("[UserName]", AuthTable, UserName)
          dbuser = CurrentUser()

          If dbuser = AuthUser Then

          DoCmd.OpenForm MenuItem, , , , acFormAdd

          ElseIf IsNull(AuthUser ) Then
          MsgBox "Accessor with User Name " & [dbuser] & " is NOT
          authorized to perform the selected action. Please contact the system
          administrator for access.", vbCritical, "Not Authorized"
          End If

          Exit_Menu_Secur ity_Click:
          Exit Sub

          Err_Menu_Securi ty_Click:
          MsgBox Err.Description
          Call LogError(Err.Nu mber, Err.Description ,
          "Menu_Security_ Module", , False)
          Resume Exit_Menu_Secur ity_Click
          End Sub

          Comment

          • Mike

            #6
            Re: Command Button Code

            On Sep 20, 11:32 am, "Allen Browne" <AllenBro...@Se eSig.Invalid>
            wrote:
            Change the first line of your code to:
                Public Function Security_Menu(A ctiveButton As String)
            >
            Then in the On Click property for Button1, use:
                =Security_Menu( "Button1")
            and so on for your other buttons.
            >
            --
            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.
            >
            "Mike" <i...@baltworld .comwrote in message
            >
            news:44c1ba92-56ae-4de7-8292-f07695412da2@b1 g2000hsg.google groups.com...
            On Sep 19, 10:02 pm, "Allen Browne" <AllenBro...@Se eSig.Invalid>
            wrote:
            >
            >
            >
            >
            >
            You will need to pass this information to the procedure.
            >
            For example:
            Private Sub Command3_Click( )
            Call DoSomething("Co mmand3")
            End Sub
            >
            Function DoSomething(str WhoCalled As String)
            Debug.Print "Called by " & strWhoCalled
            End Function
            >
            If you need to know which form it was a well, pass the button rather than
            its name. You can then examine its Parent.
            >
            --
            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.
            >
            "Mike" <i...@baltworld .comwrote in message
            >
            news:7df893f9-321e-495c-9a6e-b9e42373eb36@k7 g2000hsd.google groups.com...
            >
            >I am calling an event from the on click event of a command button. I
            cant however figure out how to refrence "which" button was clicked in
            the first procedure, in the second procedure... In simplistic terms I
            would like the system to know which button was clicked on the parent
            form so that it can pull specific requirements within the other
            section of code... any help is greatly appreciated...- Hide quoted
            text -
            >
            - Show quoted text -
            >
            Thanks.. I dont quite understand what your saying... here is the code
            behind the module... I simply want to be able to call this function
            instead of placing all of the code behind each button in each menu..
            am I thinking right??
            >
            Public Sub Security_Menu()
            On Error GoTo Err_Menu_Securi ty_Click
            >
                Dim MenuItem As String
                Dim UserName As String
                Dim dbuser As Variant
                Dim AuthUser As Variant
                Dim AuthTable As String
                Dim ActiveButton As String
                Dim ABSecurity As String
            >
                ActiveButton = Form_frmEntryIn terface. '*****Heres where the
            problem is********
            >
                AuthTable = "tbl_System_Use r_Menus"
                MenuItem = DLookup("Defaul tForm", "tblMenuOptions ", "CmdBtnName =
            " & "'" & ActiveButton & "'")
                ABSecurity = DLookup("CmdBtn Security", "tblMenuOptions ",
            "CmdBtnName = " & "'" & ActiveButton & "'")
                UserName = "UserName = " & "'" & CurrentUser() & "'" & "User_Menu
            = " & "'" & ABSecurity & "'"
                AuthUser = DLookup("[UserName]", AuthTable, UserName)
                dbuser = CurrentUser()
            >
                If dbuser = AuthUser Then
            >
                    DoCmd.OpenForm MenuItem, , , , acFormAdd
            >
                ElseIf IsNull(AuthUser ) Then
                    MsgBox "Accessor with User Name " & [dbuser] & " is NOT
            authorized to perform the selected action.  Please contact the system
            administrator for access.", vbCritical, "Not Authorized"
                End If
            >
            Exit_Menu_Secur ity_Click:
                Exit Sub
            >
            Err_Menu_Securi ty_Click:
                MsgBox Err.Description
                Call LogError(Err.Nu mber, Err.Description ,
            "Menu_Security_ Module", , False)
                Resume Exit_Menu_Secur ity_Click
            End Sub- Hide quoted text -
            >
            - Show quoted text
            Thanks Allen.. Works perfectly

            Comment

            Working...