[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1001
  • Last Modified:

Referring to a Control on a PARENT form

See form frmPriceFind
In design mode you will notice two RED fields.

My objective is for these 2 red fields to BOTH show the field CostPrice.

The red field on the subform does not work!

me.Parent!CostPrice

How do I refer to the [CostPrice] on the parent form.



DerekImport--2-.zip
0
Patrick O'Dea
Asked:
Patrick O'Dea
  • 4
  • 3
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
That's exactly how you refer to it:

Me.Parent.CostPrice

Except you don't do it from the ControlSource - you do it using the Subform's Current event:

Private Sub Form_Current()
  Me.CostPrice = Me.Parent.CostPrice
End Sub

0
 
Patrick O'DeaAuthor Commented:
Thank,

I am not quite there yet.
See attached.
I did what I thought you suggested but the form (frmPriceFind) crashes as you scroll through the records.
DerekImport.zip
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You've bound the "CostPrice" textbox to a field named "CostPrice", and that field is not in the Recordsource of your subform. You'll have to bind that control to a Field that is present in the Recordsource of your subform.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
BTW: I'm referring to the CostPrice textbox on the SUBFORM. In other words, you've bound the CostPrice textboxe on the SUBFORM to a field named "CostPrice", and that field is not present in the Recordsource of the Subform.
0
 
Patrick O'DeaAuthor Commented:
Thanks again LSM,

I am approaching the limits of my knowledge here.

Perhaps , if I forget the approach I have explained and merely tell you my objective.

I want to put a (readonly)field on the sub form that is equal to ;

CostPrice on Parent Form * Markup% on Subform.

What is the best way to achieve this?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Add a Textbox on your subform. Name it "txCalcPrice". The Textbox should be UNBOUND - that is, there should be NOTHING in the control's ControlSource property.

In the Subform's Current Event, add this code:

Private Sub Form_Current()
  Me.txCalcPrice = Nz(Me.Parent.CostPrice, 0) * Nz(Me.Markup_, 0)
End Sub

This basically tells Access that each time the Subform fires the Current event, Access should take the value of the Parent's form field named CostPrice and multiply it times the Subform's Field named "Markup%". The Nz() wrapper is the Null-to-Zero function, which insures that you don't get NULL errors (if the values of either of those root values were NULL, you'd likely get a runtime errors).

Note also that "Markup%" is a poor choice for the name of your control and can cause some frustration and troubles down the road as you must maintain and extend the application. You should use ONLY AlphaNumeric values for those names, so instead of Markup% a better choice would be MarkupPct or somethin of that nature.
0
 
Patrick O'DeaAuthor Commented:
Thanks LSM,

That was a superb answer.

Your patience and descriptive powers are much appreciated.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now