Trying to set a field value based on another form

G

Gina K

I have a form with several subforms:
frmDataEntryGrp
has the subform
frmDataEntrySubGrp
which has the subform
frmTimeDESubGrp
which has the subform
frmTimeTestRank2

The frmTimeTestRank2 is based on a query that ranks the “Results†field on
my frmTimeDESubGrp. Once I have entered my results in the frmTimeDESubGrp
form, I click a button on that form to requery my frmTimeTestRank2, thereby
assigning data to a field called “rank†on the frmTimeTestRank2.

Private Sub cmdScoreEvent_Click()

DoCmd.Save

Forms!frmDataEntryGrp!frmDataEntrySubGrp!frmTimeDESubGrp!frmTimeTestRank2.Requery

End Sub

I’d like to then assign the value of the field “Rank†(from the
frmTimeTestRank2) to the “Place†field on frmTimeDESubGrp. I played around
with it and tried to add another line to my code to do just that, but I can’t
seem to get it to work. Any assistance would be greatly appreciated.
 
D

Douglas J Steele

When referring to subforms, you need to ensure that you're referring to the
subform control on the form that holds the subform (the names may not be the
same as the form that's being used as the subform), and then look at the
Form property of that control:

Forms!frmDataEntryGrp!frmDataEntrySubGrp.Form!frmTimeDESubGrp.Form!frmTimeTe
stRank2.Form.Requery

If you added the subform by dragging the form to be used as the subform onto
the parent form, the subform control name should be the same as the form
being used as a subform. If you added the subform by adding a subform
control from the tool box, and providing the information required, the
subform control may be named something like Child1 (where the digit 1 will
vary)
 
G

Gina K

Great! The requery works; thanks for your help!

Now I have a further question: How can I take the “Rank†value returned by
the qryTimeTestRank2 and populate the “AutoPlace†field on my frmTimeDESubGrp
(record source: qryTimeDESubGrp)?

Thanks again.
 
D

Douglas J Steele

Something like:

Forms!frmDataEntryGrp!frmDataEntrySubGrp.Form!frmTimeDESubGrp.Form!AutoPlace
=
Forms!frmDataEntryGrp!frmDataEntrySubGrp.Form!frmTimeDESubGrp.Form!frmTimeTe
stRank2.Form!Rank
 
G

Gina K

Thanks, but now I'm getting run time error 2455, You entered an expression
that has an invalid reference to the property form/report.

Any idea why? I've checked and double-checked my form names...
 
D

Douglas J Steele

Try breaking it down into little pieces.

Put in a message box that refers to

Forms!frmDataEntryGrp!frmDataEntrySubGrp.Form!frmTimeDESubGrp.Form!frmTimeTe
stRank2.Form!Rank

Does it return the value you expect?

Assuming that AutoPlace has a value before you try to assign the value from
the subform, put another message box that refers to

Forms!frmDataEntryGrp!frmDataEntrySubGrp.Form!frmTimeDESubGrp.Form!AutoPlace

Does it return the value you expect?

If both of those references appear correct, then I'm not sure what other
advice I can give you.
 
G

Gina K

Thanks so much! I finally figured it out!

Douglas J Steele said:
Try breaking it down into little pieces.

Put in a message box that refers to

Forms!frmDataEntryGrp!frmDataEntrySubGrp.Form!frmTimeDESubGrp.Form!frmTimeTe
stRank2.Form!Rank

Does it return the value you expect?

Assuming that AutoPlace has a value before you try to assign the value from
the subform, put another message box that refers to

Forms!frmDataEntryGrp!frmDataEntrySubGrp.Form!frmTimeDESubGrp.Form!AutoPlace

Does it return the value you expect?

If both of those references appear correct, then I'm not sure what other
advice I can give you.
 

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