Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-17
5
Medium Priority
?
284 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
[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
  • 3
  • 2
5 Comments
 
LVL 85
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 85
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 85

Accepted Solution

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

Forms!frmProjectBudget.subfrmProjectBudgetDetails.Form.Text59
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 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