Populate a field on a subform from data in a pop-up modal form

T

texasyankee

My main form contains a subform (one to many relationship). When user
completes the main form, they click on a button which opens a pop-up modal
form requesting information. When user clicks OK, I'm trying to get a value
from the modal form to copy to a field on the subform.

I put a OnClick macro on the OK button and an OnMouse down function to set
the value to the subform field but get "can't find the form (which is my
subform) referred in a macro expression".

Am I even going about this the correct way?
 
S

Steve Schapel

Texas,

You'll have to fully reference the control on the subform as being part
of the main form, e.g.
[Forms]![NameOfMainFOrm]![NameOfSubform]![NameOfTextbox]
 
T

texasyankee

I created a macro and placed it OnClick on modal form. It contains:
Open form with my main form name
Open form with my subform name
Set Value Item: [Forms]![MainForm]![Subform]![FieldName], and with set value
expression = [Forms]![modal form]![FieldName]

When I click OK on my modal form, Access thinks the subform name is a field
and not a form name. When I click OK on the error message dialog, the Action
Failed dialog shows Condition: True, Action Name: Set Value; Argument
[Forms]![MainForm]![Subform]![FieldName] followed by a number.
I used expression maker so I know everything is spelled correctly.

Any idea about what I might be doing wrong? Thanks much for your help.

Steve Schapel said:
Texas,

You'll have to fully reference the control on the subform as being part
of the main form, e.g.
[Forms]![NameOfMainFOrm]![NameOfSubform]![NameOfTextbox]

--
Steve Schapel, Microsoft Access MVP
My main form contains a subform (one to many relationship). When user
completes the main form, they click on a button which opens a pop-up modal
form requesting information. When user clicks OK, I'm trying to get a value
from the modal form to copy to a field on the subform.

I put a OnClick macro on the OK button and an OnMouse down function to set
the value to the subform field but get "can't find the form (which is my
subform) referred in a macro expression".

Am I even going about this the correct way?
 
S

Steve Schapel

Texas,

It is not correct to use an OpenForm action with respect to the subform.
A subform is a control on a main form, it is not a form. So, remove
that line in your macro.

The expression argument in the SetValue action should be simply:
[FieldName]

(… or we should more correctly refer to it as [ControlName] - fields
belong to tables and queries, forms do not have fields.)
 
T

texasyankee

Thanks for the help.

I've removed the open form actions, and I changed the Set value as follows:
Item [controlname]
Expression [controlname]

When I click OK on my modal form, I get "The object doesn't contain the
automation object 'xxx'. Not sure what automation object means but the
control I'm trying to set is not on the modal form, it's on a subform which
resides on my main form.

Steve Schapel said:
Texas,

It is not correct to use an OpenForm action with respect to the subform.
A subform is a control on a main form, it is not a form. So, remove
that line in your macro.

The expression argument in the SetValue action should be simply:
[FieldName]

(… or we should more correctly refer to it as [ControlName] - fields
belong to tables and queries, forms do not have fields.)

--
Steve Schapel, Microsoft Access MVP
I created a macro and placed it OnClick on modal form. It contains:
Open form with my main form name
Open form with my subform name
Set Value Item: [Forms]![MainForm]![Subform]![FieldName], and with set value
expression = [Forms]![modal form]![FieldName]

When I click OK on my modal form, Access thinks the subform name is a field
and not a form name. When I click OK on the error message dialog, the Action
Failed dialog shows Condition: True, Action Name: Set Value; Argument
[Forms]![MainForm]![Subform]![FieldName] followed by a number.
I used expression maker so I know everything is spelled correctly.

Any idea about what I might be doing wrong? Thanks much for your help.
 

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