Solved

Referring to a Control on a PARENT form

Posted on 2011-02-20
7
944 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now