Find what button was clicked

G

Guest

On my form I have 5 choices (each opens a form). The form's display will
change according to what was clicked from the previous form. (eg hide, or
display controls)

What is the code to trap the last button or control clicked.

I have done this years ago back in Access2 but cannot remeber how.
Thanks
 
K

Ken Snell [MVP]

Assuming that the button that was clicked still has the focus, use
Screen.ActiveControl.Name
to get the name of the button.
 
R

Roger Carlson

One way to do this is to use the OpenArgs parameter of the form. You can
send information from one form to another with this parameter. So assuming
you have a button named Button1 (and I hope it's not) you can do this in its
OnClick event:

stDocName = "customer2"
DoCmd.OpenForm stDocName, , , , , , "Button1"

In the Customer2 form, you would read the OpenArgs string in the OnLoad
event and use it somehow. For instance, you could set this value to the
caption of a label to display which button was pushed. Something like this:

Private Sub Form_Load()
Me.Label10.Caption = Nz(OpenArgs, "")
End Sub

This will cause the value "Button1" to appear in the label when the second
form is opened.

Note: I usually use the Nz function in case the form is opened without that
argument. Under some circumstances (like if you were assigning the value to
a variable) a Null value in the OpenArgs will cause an Error.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top