Solved

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

Posted on 2013-06-17
5
271 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

680 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