473,586 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8646
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" <in**@baltworld .comwrote in message
news:7d******** *************** ***********@k7g 2000hsd.googleg roups.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...@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:7d******** *************** ***********@k7g 2000hsd.googleg roups.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
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:

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
Sep 20 '08 #4
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" <in**@baltworld .comwrote in message
news:44******** *************** ***********@b1g 2000hsg.googleg roups.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:7d******** *************** ***********@k7g 2000hsd.googleg roups.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

Sep 20 '08 #5
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:44******** *************** ***********@b1g 2000hsg.googleg roups.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:7d******** *************** ***********@k7g 2000hsd.googleg roups.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
Sep 20 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3998
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 extra step is necessary. This causes the "graph" function to execute when the button is created: Button(root, text='OK', command=graph(canvas))) ...
2
3236
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. My button bar is implemented a Frame subclass, which takes the button dictionary as an argument and displays the buttons on the screen: class...
13
4744
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 like this: %@ Language=VBScript %> <!--#include file="includes/openconnection.asp"-->
8
11828
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 grid of buttons in a loop and they all have the same purpose so they need to call the same method, within this method they need to change the...
2
9280
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 reads "Invalid use of null". The remainder of the options in the Command Button Wizard are then unavailable and the button wil not work. The only...
9
5715
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
4956
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 for things like delete, save, edit, cancel buttons - in the footer, or on the form detail section? 2. If in the footer, how do you add them to the...
4
4787
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 opens up with the record that corresponds to the one on the cont. form. I put that same code for the OnClick of an image control (i.e. the user...
3
18699
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, working with complex reports is tricky Assumption: Reader of this article have basic knowledge of creating data reports. Creating a Parent-Child...
16
2712
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 database has hundreds of forms and reports. I was asked to go through all the menu forms and determine if all the buttons worked, if there were any...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.