?
Solved

Referring to a Control on a PARENT form

Posted on 2011-02-20
7
Medium Priority
?
991 Views
Last Modified: 2012-06-27
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
Comment
Question by:Patrick O'Dea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 85
ID: 34939041
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
 

Author Comment

by:Patrick O'Dea
ID: 34939071
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
 
LVL 85
ID: 34939109
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
Technology Partners: 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!

 
LVL 85
ID: 34939115
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
 

Author Comment

by:Patrick O'Dea
ID: 34939149
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
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 34939167
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
 

Author Closing Comment

by:Patrick O'Dea
ID: 34939217
Thanks LSM,

That was a superb answer.

Your patience and descriptive powers are much appreciated.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question