• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 98
  • Last Modified:

Adding field together

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
Jass Saini
Asked:
Jass Saini
  • 10
  • 10
  • 4
  • +1
2 Solutions
 
PatHartmanCommented:
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
 
Jass SainiAuthor Commented:
So I am sorry where in the query should I do this
0
 
Jass SainiAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
PatHartmanCommented:
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
 
Jass SainiAuthor Commented:
Ok..I have a query ....but it will not allow me to update or data input into the empty fields.
0
 
Nick67Commented:
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
 
Jass SainiAuthor Commented:
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
 
Nick67Commented:
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
 
PatHartmanCommented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
Jass SainiAuthor Commented:
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
 
Nick67Commented:
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
 
Jass SainiAuthor Commented:
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
 
Nick67Commented:
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
 
Jass SainiAuthor Commented:
I clicked on it...but can't access it...  Here you go
Database10.accdb
0
 
Nick67Commented:
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
 
Jass SainiAuthor Commented:
Do you want me to send it again
0
 
Nick67Commented:
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
 
Jass SainiAuthor Commented:
Thank you for helping....but for some reason when I right click it does not give me an option to do a SaveAs
0
 
Nick67Commented:
With IE 11, it is certainly an option.
Here it is on a OneDrive Link
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
.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
 
Nick67Commented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Ahhh ... I'm using Chrome and FireFox. Those browsers behave differently, it would seem
0
 
Nick67Commented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I can download that one on my machine, using Chrome. Not sure if QT is installed or not.
0
 
Nick67Commented:
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
 
Jass SainiAuthor Commented:
Thanks..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 10
  • 10
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now