473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Saving a record in a suborm with code

I set the OnExit property of the "Cost" field in subform
"subJobDetail" to save the record (see below). Then I call a global
sub to copy the [=sum([cost])] calculated field to a field in the
subform "subJob". The record in "subJob" displays the "writing"
(pencil) icon for the record but does not update visually until I
enter and exit a second field "Markup" that is identically coded.

How do I write code to save the record in the subform "subJob"

Note: Stepping through the code in debug mode works perfectly.

What is the solution?
Code in the subform:
========================
Private Sub Cost_Exit(Cancel As Integer)
SaveRecord
mUpdateJobGrandTotal
End Sub
========================
Private Sub SaveRecord()
If Me.Dirty Then
Me.Dirty = False
End If
End Sub
========================
Code in a module:
========================
Public Sub mUpdateJobGrandTotal()
Forms![frmCustomers]![subJob].Form![txtJobTotal] = _
Forms![frmCustomers]![subJobDetail].Form![txtSumCost] + _
Forms![frmCustomers]![subJobDetail].Form![txtSumMarkup]

End Sub
========================
Nov 12 '05 #1
2 1752
Updating the calculated fields is a lower priority task in Access, so it
completes your code before they are updated.

You could try the Recalc method to force the update before running
mUpdateJobGrandTotal.

Alternatively, you could perform a DSum() operation directly on the
subform's table instead of relying on the calculated total. This has the
added advantage that it works correctly even if the subform has a filter
applied.

Ulimately, though, the question arises as to why the total is being stored
in the main form. Is there a good reason for this? Or would it be a better
design just to calculate the total when you need it so it can never be
wrong?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Douglas Buchanan" <db*********@comcast.net> wrote in message
news:db*************************@posting.google.co m...
I set the OnExit property of the "Cost" field in subform
"subJobDetail" to save the record (see below). Then I call a global
sub to copy the [=sum([cost])] calculated field to a field in the
subform "subJob". The record in "subJob" displays the "writing"
(pencil) icon for the record but does not update visually until I
enter and exit a second field "Markup" that is identically coded.

How do I write code to save the record in the subform "subJob"

Note: Stepping through the code in debug mode works perfectly.

What is the solution?
Code in the subform:
========================
Private Sub Cost_Exit(Cancel As Integer)
SaveRecord
mUpdateJobGrandTotal
End Sub
========================
Private Sub SaveRecord()
If Me.Dirty Then
Me.Dirty = False
End If
End Sub
========================
Code in a module:
========================
Public Sub mUpdateJobGrandTotal()
Forms![frmCustomers]![subJob].Form![txtJobTotal] = _
Forms![frmCustomers]![subJobDetail].Form![txtSumCost] + _
Forms![frmCustomers]![subJobDetail].Form![txtSumMarkup]

End Sub
========================

Nov 12 '05 #2
> Updating the calculated fields is a lower priority
task in Access, so it completes your code before
they are updated.
Is code considered a calculated field?
Isn't this a calculated field: =[txtSource]*[txtFactor]
You could try the Recalc method to force the update
before running mUpdateJobGrandTotal.
mUpdateJobGrandTotal is the problem.
Alternatively, you could perform a DSum() operation
directly on the subform's table instead of relying
on the calculated total. This has the added
advantage that it works correctly even if the subform
has a filter applied.
This sounds like the direction I'll take. Thank you.

I chose the code because I thought that it would run more quickly and
with less overhead than DSum(). You see the subform already displays the
Total through a calculated field without any code. The code is just
copying that calculated field to another subform where the owner of the
information observes the value and makes a one-time judgement based on
that value, then enters an arbitrary value into a second field in that
subform.
Ulimately, though, the question arises as to why the total >is being

stored in the main form. Is there a good reason >for this? Or would it
be a better design just to calculate >the total when you need it so it
can never be wrong?

With the code running properly it could never be wrong. This form is the
only access to the table. Any values added to the subform updates the
Total.

The Total is being displayed on this form because in this application
this form is the only place where this value is seen. There are
currently no plans for printed reports. Should printed reports be added
the total will not come from this location. It would be caluclated on
the report from a query of the values in the table.

Doug

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jack | last post by:
Hi, I need to build a asp page where it would serve as a data entry record page as well as display page for records saved. This page should also allow editing of records that has been saved. ...
3
by: CSDunn | last post by:
Hello, I have an Access 2000 Project in which the data comes from a SQL Server 2000 database, and multiple users need to be able to see new records as each user adds records. The users also need...
1
by: Cillies | last post by:
Hello all, I was recently browsing the forum and remembered seeing a message relating to MS Access Bugs/Flaws. The thing is I cannot find that thread anymore, and so was wondering does anyone know...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
11
by: kaosyeti | last post by:
i have a form that records 9 fields into a table. on that form i have a 'done' button to close the form. right now, if the form is fully filled in, but you don't press 'enter' before you click...
18
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
1
by: google | last post by:
I have a form with several subforms. Users enter the data, then on the parent there is a command button that runs code to generate a .pdf document from a report based on the data they are working...
3
by: Andy_Khosravi | last post by:
I'm having a problem with an entry form on one of my applications. It would appear that the save action is sometimes not working, and is generating no error when it fails. I'm hoping one of you may...
1
by: Cesar Zapata | last post by:
Hi, I have a a bound subform and what i'm trying to do is do check if some criteria applies before saving the record and trigger a macro. basically this is what I got. Date Received ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.