473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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...
Sep 20 '08 #1
5 8625
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the...
2
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make....
13
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is...
8
by: dakman | last post by:
Recently, I have been needing to do this alot and I can never find a way around it, the main reason I want to do this is because for example in the application I am making right now, it creates a...
2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
9
by: Melissa | last post by:
What is the code to delete a command button from a form? Can the code be run from the click event of the button to be deleted? Thanks! Melissa
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
4
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
16
by: Steve | last post by:
I am working on a database that has a main menu, many sub-menus and some sub-sub-menus. They are all forms that have numerous command buttons on them to open forms and reports in the database. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.