Solved

Referring to a Control on a PARENT form

Posted on 2011-02-20
7
978 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
  • 4
  • 3
7 Comments
 
LVL 84
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 84
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 84
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 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

726 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