Solved

Adding field together

Posted on 2014-12-11
27
85 Views
Last Modified: 2014-12-17
I need to add field1 and feild2 into field3...is that better to make field3 a calculated field or doing it on the form.  If it's better on the form...where on the form??
0
Comment
Question by:Jass Saini
  • 10
  • 10
  • 4
  • +1
27 Comments
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
Comment Utility
I prefer to do simple calculations like this in the query.  Then I can bind the calculated field to the form and don't need to add code to make it update.

Select Nz(fld1,0) + Nz(fld2, 0) As fld3

Notice the Nz() functions.  If you are positive that your data will never contain null values then you don't need them.  Otherwise you do.
0
 

Author Comment

by:Jass Saini
Comment Utility
So I am sorry where in the query should I do this
0
 

Author Comment

by:Jass Saini
Comment Utility
Hello Pat,

Sorry.... I was using a query.  But I could find how to input into my blank fields, so now I am using a master/child form.  I need to make the calculation field in the subform
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
using a subform doesn't change the suggestion.  Every form should use a query as its RecordSource.

If you insist on putting the calculation in the subform, add the following to the ControlSource for field3

=Nz(fld1,0) + Nz(fld2, 0)

The "=" tells Access that this is not a bound control.  The calculation will be updated if either fld1 or fld2 is changed.  Other solutions involve code.
0
 

Author Comment

by:Jass Saini
Comment Utility
Ok..I have a query ....but it will not allow me to update or data input into the empty fields.
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 250 total points
Comment Utility
Here is a sample using a query
@PatHartman has the right of it
Ok..I have a query ....but it will not allow me to update or data input into the empty fields.

Open your query.
Can you alter fields there?
Then you have created a read-only query.
There are many causes of that.
The main ones are:
Multiple tables used that do not have direct realtionships
Primary key fields not included in the query
Unique records (DISTINCT) option in play.

Your query must be editable before your form will be!
CalculateControl.mdb
0
 

Author Comment

by:Jass Saini
Comment Utility
So Pat...if I use    =Nz(fld1,0) + Nz(fld2, 0)  then it shows ...let's say fld1 is 74 and fld2 is 1...it shows 741 instead of 75
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Then your table may have a problem.
"74" + "1" results in 741
74 + 1 results in 75.

Are you storing numbers as text by accident, or on purpose?
=CLng(Nz(fld1,0)) + CLng(Nz(fld2, 0))
can bandage that over -- but if you aren't storing numbers as text for a reason, then you should fix the table and use Pat's formula
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
As Nick suggested, the fields are defined as text which is why they concatenated rather than summed.  CLng() will convert them to Long Integers but that may or may not be the correct data type.  What data type are you expecting?
0
 
LVL 84
Comment Utility
Ok..I have a query ....but it will not allow me to update or data input into the empty fields.
If those "empty fields" are your calculated fields, then you won't be able to update them.
0
 

Author Comment

by:Jass Saini
Comment Utility
No not calculated fields...I may have found the problem.  Is it okay to import a excel sheet and use that as a table???
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Is it okay to import a excel sheet and use that as a table???
Import it as a new table, and it becomes and Access table and all is well
Link to it, so it remains an Excel sheet and then there are problems.

MS lost a patent case to a Guatemalan gentleman.
They have not purchased or leased his patents
Instead, they broke Access's ability to update linked Excel sheets to not violate his patent.
Data on a linked Excel sheet is read-only in Access
0
 

Author Comment

by:Jass Saini
Comment Utility
I made a table using a excel file.  I tried running that table with another table for a query..query is fine.  But when I make the form the blank fields..I can not enter in data.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 26

Expert Comment

by:Nick67
Comment Utility
You downloaded and look at the sample I posted here, right?

It had a table, form and query that shows how it all works.
Post a sample mdb file of your own if you can and wish.
0
 

Author Comment

by:Jass Saini
Comment Utility
I clicked on it...but can't access it...  Here you go
Database10.accdb
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Ah,

EE has a bug at the moment.
for .accdb files you must right-click and SaveAs | All files and then give it the .accdb ending.
I'll have a look.
0
 

Author Comment

by:Jass Saini
Comment Utility
Do you want me to send it again
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Ok,

Here is your file returned.
I have altered table Final_table
I have altered Query1
I have altered form Final_table.

I have created the 4 calculated fields/controls that I think you wanted
I have put them all on the form and arranged them
Calculated fields generally are not stored in the table.  I have removed them.
Query1 had no join.  I added it
Query1 does the calculating, and not the form

As noted above, for .accdb, right-click and SaveAs | All files | database10 v1.accdb
Database10-V1.accdb
0
 

Author Comment

by:Jass Saini
Comment Utility
Thank you for helping....but for some reason when I right click it does not give me an option to do a SaveAs
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
With IE 11, it is certainly an option.
Here it is on a OneDrive Link
0
 
LVL 84
Comment Utility
.but for some reason when I right click it does not give me an option to do a SaveAs
If you're trying to download the file Nick posted, then you may just try clicking on it directly. I can do that, and it downloads fine on my machine.
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
In IE 11, accdb files try to open as html on a left-click.
Have since July.  Bug report filed, but the issue is not fixed.  Reported in the Glitches group too
Right-click | SaveAs | All files | name it *.accdb works.

But not a left-click
0
 
LVL 84
Comment Utility
Ahhh ... I'm using Chrome and FireFox. Those browsers behave differently, it would seem
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Yup,
Chrome, it works ok for.
Although boag200 runs Chrome without Quicktime and he couldn't run this attachment.
IE 11 without Quicktime would.
mapV3.mdb
0
 
LVL 84
Comment Utility
I can download that one on my machine, using Chrome. Not sure if QT is installed or not.
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Boag2000 could download it.
When he opened it without IE as the default browser it threw all sorts of errors.
It's got a WebBrowser control that displays Google Static maps with pins
0
 

Author Closing Comment

by:Jass Saini
Comment Utility
Thanks..
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.

Join & Write a Comment

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

743 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

12 Experts available now in Live!

Get 1:1 Help Now