473,386 Members | 1,705 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.

Subform Sum error

174 128KB
Hello,

I have a error for Sum's in frmAggrSub. I have 4 unbound text boxes in the footer, 1 is a percent of qryProduction so I can understand if its 0 than a error. However the other 3 only Sum entered numbers in the subform. Any help is appreciated

Edit: The uploaded file has a default value of 0 in AggrPerc textbox in frmAggrSub. I just corrected that, it was causing data entry issues. But the rest I stated is still happening
Apr 4 '19 #1
23 1804
NeoPa
32,556 Expert Mod 16PB
You need to put the full question in the thread. Expecting people to upload your database in order to determine what the question should be is not acceptable.

I do explain that elsewhere but it helps that all instances are flagged this way so anyone looking and seeing what goes on here is under no illusion how things are supposed to be done.

I explained before about technical questions but I'll repeat they need to be expressed fully, carefully and using the best terminology you can manage. If you talk about controls but don't explain they're on a Form, or even a SubForm, then our ability to help is severely curtailed. Reading through your question and fixing any problems is expected in all cases but particularly for OPs (OP = Opening Post as well as Opening Poster. It's used here as the former).

Ideally, and very few manage this level of competence, but ideally, questions should be posted and an answer given and that's the end of it. Imagine the value to someone Googling for their problem to find such threads. Simples. Question asked and answered. Perfect. In real life we just aim for that target. It does require a little effort, but not only is that reasonable when asking for assistance, it also has a way of benefitting you too in less obvious ways.
Apr 4 '19 #2
williamson1979
174 128KB
I don't know how to explain other than I have a unbound textbox using the sum feature that returns a error unless what seems to be a totally unrelated field in another has a value greater than 0?
Apr 4 '19 #3
williamson1979
174 128KB
Im sorry Im aggravating you but I made the changes off other advice offered so now Ive encountered issues that has risen from that which are in my last 2 post. Ill figure out thanks

Mod if possible please delete my account. Thanks Twinny I eally appreciated your help.
Apr 4 '19 #4
williamson1979
174 128KB
You need to put the full question in the thread. Expecting people to upload your database in order to determine what the question should be is not acceptable.

I simply post what I see is not working. I uploaded the file in case anyone thought it would be helpful since I do not know the technical terms. I never ask anyone to open it. I know the help offered is free and on your time but understand I don't know enough to be specific.. Just delete the threads and Ill repost with different wording.
Apr 4 '19 #5
NeoPa
32,556 Expert Mod 16PB
Aggravating is probably not the right word. Frustrating is nearer the mark.

I'm not simply looking to put you down. I know what a mess we can all get into when things are explained in an imprecise way and questions are asked simply as they occur to the poster rather than them spending time and effort to make them make sense to people who aren't in the room with them. IE. If the whole situation isn't explained but we're left to guess at much of what constitutes the problem.

I say these things because it's what works. Frankly we've seen the meandering threads that you've started so far and they get very little done in a lot of time. It's very little help to you and does very little for us or the website. If you really feel that explaining your problem in a clear and concise way is beyond you then perhaps here isn't where you need to be.

I can honestly say that I feel only that it's a shame we can't make some better contact. I don't feel you've done anything to upset us here. There just seems too big of a gap between how this works (and for practical reasons has to work) and how you think and work. We wish you only the best of luck.
Apr 5 '19 #6
williamson1979
174 128KB
I tried a new post. One problem only mentioned. I hope that will be clear and understandable. I’ll worry about the other stuff once that question gets somewhere. Actually a few post got nice results. It’s the little things to tie it all together is harder for me to explain.
Apr 5 '19 #7
williamson1979
174 128KB
Inserting this into the query for the subform eliminated the #Num and #Error errors from the subform. I wish this thread would have went somewhere though because it still makes no sense why three of the four fields that were not using ProdSold or ProdWaste for calculations were effected by this.

Expand|Select|Wrap|Line Numbers
  1. AggrPerc: IIf([ProdSold]=0 And [ProdWaste]=0,0,[AggrUsed]/([ProdSold]+[ProdWaste]))
Apr 7 '19 #8
NeoPa
32,556 Expert Mod 16PB
I don't see anywhere what the whole query looks like in SQL so I can't explain everything for you. However, I did notice one problem with the formula you posted. It seems it should probably be :
Expand|Select|Wrap|Line Numbers
  1. IIf([ProdSold]=0+[ProdWaste]=0,0,[AggrUsed]/([ProdSold]+[ProdWaste]))
If you're still experiencing problems with your query try posting in its SQL here and we can try to have a look (Also check out How to Debug SQL String).
Apr 7 '19 #9
williamson1979
174 128KB
Thanks. I’ll update with your code. What I put seemed to correct the errors though it might not be the best solution . My biggest confusion was 3 fields of the 4 aren’t linked nor do they divide. They only sum whatever numbers are entered. The other I understand since it uses a field from the main form which has the possibility to be 0. So I can’t wrap my mind around why but clearly there is a why I’m just missing it.

Anyway as I say I’ll enter your code and go from there. If I notice anymore glitchy behavior I’ll post sql.
Apr 7 '19 #10
williamson1979
174 128KB
I’ll read the link you posted as well.
Apr 7 '19 #11
NeoPa
32,556 Expert Mod 16PB
It doesn't surprise me that many (most) of the situations that had problems disappeared with your earlier code. There are just some possible scenarios where your code would continue to error, even if you haven't seen them yet.

As a matter of interest can you tell me where and/or why? IE. Have you understood the change and why I suggested it?

PS. Yes. Read the link. Most of the real value is in the articles. These are explanations for the most commonly experienced problems, which is why it was worth the extra effort to produce them.
Apr 7 '19 #12
williamson1979
174 128KB
As a matter of interest can you tell me where and/or why? IE. Have you understood the change and why I suggested it?

Ive just had time to take a quick glance but the first thing I see is "AND" has been replaced with"+". My assumption "And" might be for combining a text string rather than math so you added "+"?
Apr 7 '19 #13
NeoPa
32,556 Expert Mod 16PB
No. That's not correct. It's a real edge-case as you probably don't expect to deal with negative numbers, but defensive coding generally means following the logic rather than simply getting to approximately the same destination.

Consider what happens with your code, then separately with my code, if you had the values :
Expand|Select|Wrap|Line Numbers
  1. [ProdSold]=3
  2. [ProdWaste]=-3
Neither is zero, yet the Sum of the two is zero. The Divide by zero error occurs if the Sum is zero and not only in the case where both values are zero.

This is more important than it appears. You may say "But in my scenario negative values would never occur.", but that would be missing the point.

This code may be copied elsewhere with the confidence that comes from it working reliably here. Wouldn't that be fun. Also, how code is read is important, just as how it's written is. If someone is reading your work later are they to be sent on a wild goose chase trying to determine why you've used two separate tests joined with an AND, or will they see code that immediately makes logical sense because it matches the use later in the same line?

These aren't going to stop your system working but they're opportunities to make you aware of issues that may otherwise trip you up. If you begin things the right way then the learning curve avoids some unnecessary missteps.
Apr 7 '19 #14
williamson1979
174 128KB
Makes sense however when I entered your code I got #num, #Div/0 and #Error values with the ProdTotal "0".

Edit: The #Error are in unbound boxes and simply gives the error because the bound boxes are in error, jeez took me a week for that to click.
Apr 7 '19 #15
williamson1979
174 128KB
A little detail. ProdTotal is for a finshed product but if nothing is produced it will be 0. Aggregate can still be added or sold regardless so values will be entered. But the subform has Used and Percent of as well that are directly related to ProdTotal.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblAggr.AggrID, tblAggr.AggrType, tblAggr.AggrUsed, IIf([ProdSold]=0+[ProdWaste]=0,0,[AggrUsed]/([ProdSold]+[ProdWaste])) AS AggrPerc, tblAggr.AggrSold, tblAggr.AggrAdded
  2. FROM tblProduction INNER JOIN tblAggr ON tblProduction.ProdID = tblAggr.AggrID;
Apr 7 '19 #16
NeoPa
32,556 Expert Mod 16PB
I've just looked again at what I suggested in post #9 and realised I mucked it right up. Ignore that one. It's rubbish.

What I SHOULD have said was :
IIf([ProdSold]+[ProdWaste]=0,0,[AggrUsed]/([ProdSold]+[ProdWaste]))
Let's go from there and see if we still have any issues.

Everything I said in posts #12 & #14 was based on my having posted that in #9. If you go through it again it may actually sound like I know what I'm talking about this time (blush).
Apr 7 '19 #17
williamson1979
174 128KB
No problem I’ll look at it and try it out.
Apr 8 '19 #18
williamson1979
174 128KB
I updated the code Id posted with yours. It displays properly in form view and report view. Thanks

How would I update this code to match the code you gave me a couple post ago? I would think this is correct but in form view it displays 0.00 but in report view it displays Div/0. I have roughly 5 instances of this I'd like to get corrected.
Expand|Select|Wrap|Line Numbers
  1. =IIf([txtProdTotal]=0,0,[txtAsphUsed1]/[txtProdTotal])
Apr 10 '19 #19
NeoPa
32,556 Expert Mod 16PB
That depend entirely on where this is. In SQL it should be fine. If you have it in VBA anywhere then it could be a problem. Even in the Expression Service, which handles expressions in Controls, it should resolve perfectly safely.

Exactly where are the 5 and can you give an example of one of them please (assuming this isn't the example as I see nothing wrong with it).
Apr 10 '19 #20
williamson1979
174 128KB
Is it SQL when it’s entered into the forms property box? That was copied and pasted directly from there once I clicked on the text box, view properties, control source. All 5 are in my main report form. They are all exactly the same except what’s being divided by the ProdTotal. I thought it seemed fine from what I’d already did and what you showed me except yours involved a multi step calculation where this one does not. Just the one you did shows the same in both form and report view. The one I just showed you shows fine in form view but the div error on the report.

It’s definitely not coded on vba though.
Apr 10 '19 #21
williamson1979
174 128KB
Expand|Select|Wrap|Line Numbers
  1. [AsphUsed1]/[ProdTotal] AS AsphPerc1

Since you mentioned SQL I started looking into the query for the report. The above code apparently did not update with my changes in the form as the one you first helped me on. Is it ok to just edit the SQL directly to show
Expand|Select|Wrap|Line Numbers
  1. IIf([txtProdTotal]=0,0,[txtAsphUsed1]/[txtProdTotal])
Apr 10 '19 #22
williamson1979
174 128KB
Sorry Neo for 3 post in a row. Since your response to where is the code got my brain spinning I might have fixed it. In the query I entered this
Expand|Select|Wrap|Line Numbers
  1. IIf([ProdTotal]=0,0,[HeatNGUsed]/[ProdTotal]) AS HeatNGTon
for 1 of the instances I was speaking of and it now shows 0.0 rather than Div/0 error.
Apr 10 '19 #23
NeoPa
32,556 Expert Mod 16PB
All's well that ends well. I much prefer members finding themselves exactly what the problem is. Even if it's been explained to them but they need a little concentration time before they fully appreciate what's what. That's a lesson really learned and will stay with you.
Apr 13 '19 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mary Ann | last post by:
I have a main form with 4 subforms. One of the subforms reflects other costs/miscellaneous charges that an account might be assessed. The main form includes a field with a total pulled from that...
8
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
3
by: Charlene | last post by:
I have an Invoice/Invoice Details form/subform. In the page footer of the Invoice Details subform I have a textbox with the control source set to =Sum(). I then pull this value into the main form...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
2
by: Bill Stock | last post by:
I have a subform which is causing a 3314 (Field can't contain a null value because required is set to True) error. I solved this problem by trapping it in the before update event. But then I...
10
by: robert d via AccessMonster.com | last post by:
I have a global error handler that up until today has been working flawlessly. Let me first provide the relevant code **************************************************************** On Error...
1
by: dBNovice | last post by:
Please help! I have 3 forms: Task, Subtask, Elements. Elements is a subform of Subtask and Subtask is a subform of Task. I am able to navigate from Task to Subform to Element and from Element to...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
2
by: Andreas | last post by:
Hello together, I want to calculate a sum in subform from a subsubform (sounds complicated?) but I get an #error but... see below My database: I have a main form with members, each members...
4
MitchR
by: MitchR | last post by:
Good Day Folks; I have found myself in a hole I can't get out. In Access Version 2000 I have a form Called Frm_Main That contains a SubForm Frm_Main_Sub. Frm_Main_Sub's record source is a select...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.