By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

Command Button Code

P: n/a
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...
Sep 20 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You will need to pass this information to the procedure.

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

Function DoSomething(strWhoCalled 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" <in**@baltworld.comwrote in message
news:7d**********************************@k7g2000h sd.googlegroups.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...
Sep 20 '08 #2

P: n/a
On Sep 19, 10:02*pm, "Allen Browne" <AllenBro...@SeeSig.Invalid>
wrote:
You will need to pass this information to the procedure.

For example:
* * Private Sub Command3_Click()
* * * * Call DoSomething("Command3")
* * End Sub

Function DoSomething(strWhoCalled 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:7d**********************************@k7g2000h sd.googlegroups.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_Security_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_frmEntryInterface. '*****Heres where the
problem is********

AuthTable = "tbl_System_User_Menus"
MenuItem = DLookup("DefaultForm", "tblMenuOptions", "CmdBtnName =
" & "'" & ActiveButton & "'")
ABSecurity = DLookup("CmdBtnSecurity", "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_Security_Click:
Exit Sub

Err_Menu_Security_Click:
MsgBox Err.Description
Call LogError(Err.Number, Err.Description,
"Menu_Security_Module", , False)
Resume Exit_Menu_Security_Click
End Sub
Sep 20 '08 #3

P: n/a
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:

strClickedButton="command_2"

DoCmd.OpenForm "MyChildForm",OpenArgs:=strClickedButton

[...]

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
Sep 20 '08 #4

P: n/a
Change the first line of your code to:
Public Function Security_Menu(ActiveButton 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" <in**@baltworld.comwrote in message
news:44**********************************@b1g2000h sg.googlegroups.com...
On Sep 19, 10:02 pm, "Allen Browne" <AllenBro...@SeeSig.Invalid>
wrote:
You will need to pass this information to the procedure.

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

Function DoSomething(strWhoCalled 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:7d**********************************@k7g2000h sd.googlegroups.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_Security_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_frmEntryInterface. '*****Heres where the
problem is********

AuthTable = "tbl_System_User_Menus"
MenuItem = DLookup("DefaultForm", "tblMenuOptions", "CmdBtnName =
" & "'" & ActiveButton & "'")
ABSecurity = DLookup("CmdBtnSecurity", "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_Security_Click:
Exit Sub

Err_Menu_Security_Click:
MsgBox Err.Description
Call LogError(Err.Number, Err.Description,
"Menu_Security_Module", , False)
Resume Exit_Menu_Security_Click
End Sub

Sep 20 '08 #5

P: n/a
On Sep 20, 11:32*am, "Allen Browne" <AllenBro...@SeeSig.Invalid>
wrote:
Change the first line of your code to:
* * Public Function Security_Menu(ActiveButton 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:44**********************************@b1g2000h sg.googlegroups.com...
On Sep 19, 10:02 pm, "Allen Browne" <AllenBro...@SeeSig.Invalid>
wrote:


You will need to pass this information to the procedure.
For example:
Private Sub Command3_Click()
Call DoSomething("Command3")
End Sub
Function DoSomething(strWhoCalled 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:7d**********************************@k7g2000h sd.googlegroups.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_Security_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_frmEntryInterface. '*****Heres where the
problem is********

* * AuthTable = "tbl_System_User_Menus"
* * MenuItem = DLookup("DefaultForm", "tblMenuOptions", "CmdBtnName=
" & "'" & ActiveButton & "'")
* * ABSecurity = DLookup("CmdBtnSecurity", "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_Security_Click:
* * Exit Sub

Err_Menu_Security_Click:
* * MsgBox Err.Description
* * Call LogError(Err.Number, Err.Description,
"Menu_Security_Module", , False)
* * Resume Exit_Menu_Security_Click
End Sub- Hide quoted text -

- Show quoted text
Thanks Allen.. Works perfectly
Sep 20 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.