Solved

Referring to a Control on a PARENT form

Posted on 2011-02-20
7
965 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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 …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

776 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