referring to a control in a subform

G

Guest

I have a form entitled "Purchase Requisitions" and a subform entitled "PR
Details." I have a button on the subform that is called "open job," and
initiates a macro that opens a new form called "Existing Job." I want the
macro to set the value of the "Job ID" field on the new form to that which is
already listed on the subform. My setvalue line looks like this:

Item [Forms]![Existing Job]![Job ID]
Expression [Forms]![PR Details]![Job ID]

As long as I have only the "PR Details" form open the macro works. But if I
have "Purchase Requisitions" open (with "PR Details" as a subform), I get an
error message that says, " . . . can't find the form 'PR Details' referred to
in a macro expression or visual basic code. *The form you referenced may be
closed or may not exist in this database. * . . . may have encountered a
compile error in a Visual Basic module for the form."

How do I write the expression so that it works?
 
N

Nikos Yannacopoulos

Crystal,

You need to modify your reference so it looks for the control in the subform
in the form:

Item [Forms]![Existing Job]![Job ID]
Expression [Forms]![Purchase Requisitions]![PR Details]![Job ID]

HTH,
Nikos
 
S

Steve Schapel

Crystal,

Nikos's advice is correct. You can't directly refer to a control on the
PR Details form, since in fact it is not open, it is simply displayed
through the container of the main form.

However, it is simpler to omit any form reference at all. Since it is a
control on the active object (i.e. the same place where the macro is
being called from), you can just do it like this...

Item: [Forms]![Existing Job]![Job ID]
Expression: [Job ID]
 

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