Solved

Trying to write value of a calculated field on a subform to a field in a table

Posted on 2013-06-17
5
237 Views
Last Modified: 2013-06-18
I have a form bound to a table.  On the form is a subform with a calculated field.  For now the field is named Text59.  When the main form closed I have this code in the onclose event but it isn't working.  I get a message that says it can't find the subform.

????


Here's the code:

CurrentDb.Execute "Update  tblProjectBudgetHeader set ConstructionBudget = " & Forms!subfrmProjectBudgetDetails.Text59 & " Where ID=" & Me.Combo113.Column(0), dbFailOnError
0
Comment
Question by:SteveL13
  • 3
  • 2
5 Comments
 
LVL 84
ID: 39254658
You refer to a Subform like this:

Forms!NameOfTheParentForm.NameOfTheSubformCONTROL.Form.YourControl

Note "NameOfTheSubformCONTROL" - this is the name of the CONTROL on the Parent form, and may or may not be named the same as the form you're using as a Subform.
0
 

Author Comment

by:SteveL13
ID: 39254675
I must have this totally messed up.

CurrentDb.Execute "Update  tblProjectBudgetHeader set ConstructionBudget = " & Forms!frmProjectBudget.Text59.subfrmProjectBudgetDetails.Me.Combo113.Column(0) & " Where ID=" & Me.Combo113.Column(0), dbFailOnError
0
 
LVL 84
ID: 39254679
Is "Text59" the name of the control that holds the calculated data?

If so then perhaps this:

CurrentDb.Execute "Update  tblProjectBudgetHeader set ConstructionBudget = " & Forms!frmProjectBudget.subfrmProjectBudgetDetails.Text59 & " Where ID=" & Me.Combo113.Column(0), dbFailOnError

And remember that it's typically NOT a good idea to store calculated data in a field. If you have a formula to calculate the value, then you should use that formula each time you need to work with the data. This recreates the data from the source, so if the source changes, you don't have to worry with updating the ConstructionBudget each time.
0
 

Author Comment

by:SteveL13
ID: 39254697
This doesn't work either:

CurrentDb.Execute "Update  tblProjectBudgetHeader set ConstructionBudget = " & Forms!frmProjectBudget.subfrmProjectBudgetDetails.Text59 & " Where ID=" & Me.Combo113.Column(0), dbFailOnError

Here is the latest (note that I changed ID to BudgetID which is the name of the field).
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39254949
Oops ... forgot the Form call:

Forms!frmProjectBudget.subfrmProjectBudgetDetails.Form.Text59
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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 …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

747 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

14 Experts available now in Live!

Get 1:1 Help Now