Buttons and Forms

SafetyGuy

New member
Local time
Today, 04:55
Joined
Sep 1, 2015
Messages
5
Good Day!

I am working on a personal database and I want to create a form that has a series of what I call, "visual buttons" basically buttons that are pictures, that are used to navigate to another form. My question involves not the button form, but the second form. When I click on a button, I want a field on the second form to open up with generated information based on the button from the first form that was pressed. The form that opens is the same for each button, but will have a slightly different title and in one particular field in the second form, a different value. Do I need to create a separate form with the information in the "Default Value:" of the field for each form for each button or can I set it up so that when the form opens, it identifies which button it opened from and then defaults to the predesignated, say through an IIF formula for example, bit of information? Thanks in advance!

Thought I should add an example:

Click Button 1 on Form 1, Form 2 opens, Field on form 2 defaults to "Button 1"
Click Button 2 on Form 1, Form 2 opens, Field on form 2 defaults to "Button 2"

Do I have to create a separate form for each button, or is there a way to write it so that field on form 2 defaults to specific information based on button pressed?
 
Last edited:
There are many approaches you could take to this.

1) DoCmd.OpenForm has a an OpenArgs argument, so in the OpenForm command you can pass a string value to the the form. This is then present in the Form's OpenArgs property, which code on the form can read.

2) You can read Screen.ActiveControl or Screen.PreviousControl, which maintains references to the last couple of controls that had the focus. One of them will be the button you clicked. You can read this value in the Form_Open() event handler, and determine that way which button was last used.

3) You can write a value to a table on the button click, and read that value from the table when the form opens.

4) You can write a value to some other third party object or global variable (noooo) and then read from that location when the form opens.

Hope this helps,
 
There is an issue with a forms load event (and the other loading events) in that they do not work as you would like or expect. I discussed this on my webpage here:- https://sites.google.com/site/msaccess457966vmfjg/got-ya-s/form-load-events ... Now I realise that's not your question however I point you to this website because the downloadable file has what you want (I think), if you open forms 3 and then click the button, it will open form 4 and display text. I think if you explore this mechanism it will give you the functionality you want, but the rest of it might be a tad confusing!
 
Last edited:
Correction! You can use the code in form 1 and 2 however, to see the "fSetUp" function working, you will have to uncomment it!
 

Users who are viewing this thread

Back
Top Bottom