Passing variable from main form to second form

twoplustwo

Registered User.
Local time
Today, 14:56
Joined
Oct 31, 2007
Messages
507
Hi guys,

Been a while since I worked with forms.

I have a list of customers that are monitored by the team. They need to add actions to each customer against a specific contract (one to many). At the moment a customer name is selected, a list box shows the different contract, they click which contract they need to enter a record for and a secondary form loads.

The second form is loaded with the name/contract details from the main form. There is a text field where the description is entered.

Where I am stuck is passing the contract ID across to the second form. This is so they can commit the record to tblActions with the contract field key/action etc.

Any suggestions welcome.
 
Take a look at the "OpenArgs" argument when using the Docmd.openForm method.

Then in your form you can have code that will read the value of the OpenArgs property of the form.
 
Excellent, thanks B.

I assume the form stores the value when it opens even though the code isn't running?

Cheers.
 
When you pass a value in the "OpenArgs" argument, the property "OpenArgs" of the form you open will be populated with the value passed by the argument.

If you had a text box control on your form named "txtContractID", you could put the value of the "OpenArgs" property of the open form into that control with code in the on open event with code like:

Me.txtContractID = Me.OpenArgs
 
or you can get there directly

to read a control

somefield = forms!formname.form!controlname


or to run a proc IN the other form

forms!formname.someproc
 

Users who are viewing this thread

Back
Top Bottom