Passing Variable from form to Pop-Up

  • Thread starter Thread starter Allan Koodray
  • Start date Start date
A

Allan Koodray

I have a form structured as such:

* The main form is a query with a criteria specifying
department.
* The form has a linked subform (linked on department)

I would like to add another subform, that is activated by
macro, as a pop-up. I need to pass the department number
from the main form to the pop-up subform (Allowing the
user to add records to that specific department).

Allan Koodray
 
In a macro, the only way to do this is to have a macro run when the "popup"
form (not a subform!) opens and loads (with its Data Entry property set to
Yes so that it will only add records) ...this macro would read the value of
the "department number" from the main form, and write that value into the
control that is bound to the field in the form's recordsource that is to get
that value. This can be done using a SetValue macro that is run on the popup
form's OnLoad event:
Action: SetValue
ControlName: Forms![PopupFormName]![ControlToGetTheValue]
Expression: Forms![MainForm]![DepartmentNumberControl]

Note that the setup of the popup form may need to be in a main form/ subform
setup so that you can write the value to a control on the main form, link
that control/field to the appropriate linking field in the subform's
recordsource, and then you can continue. If you want to add multiple records
and don't want this setup, then you'll need code in the popup form that
writes the value of the department number into the field for each new record
being added.
 
Back
Top