Can anyone Help I am trying to use the expression builder to create an expression that returns a zero when a formula tries to divide by zero.
So far my attempts have failed.
This is what I have tried so far. I feel my logic is correct maybe my syntax is off.
Expr1: IIf(Bsheetcostdraft![CSA/SAA]=0,0,Icostcostdraft![CSA/SAA]/Bsheetcostdraft![CSA/SAA])
Can anyone guide me through this.
17 1665
Have you tried '.' instead of '!'? Also I think you made a typo with lcostcostdraft, should probably be lsheetcostdraft?
Have you tried '.' instead of '!'? Also I think you made a typo with lcostcostdraft, should probably be lsheetcostdraft?
I did try switching the "!" for "." To no avail and I know my naming conventions seem wierd but they are correct. I really stranded here. Can you even put an expression like this in the space marked field for a select query.
Yes, you can do this. What about the fields with '/' Have you tried removing those characters from the field name? This may impact other queries you have.
No Dice! Still does not work. This problem does not make any sense to me. I have two tables that hold similar information one comes from the blue sheet the other from Icost. We use two costing tools to provide information. This database holds the info then runs this query to see what the difference is pct wise between the two tools. I just designed it last week.
I think the issue is just proper coding methods.
1. Is the following reffering to controls on a form or subform and if yes which is it a form or subform?
2. Is this code in the Main form or elsewhere?
If we are dealing with code in a form name "Bsheetcostdraft", It should read more like this: - IIf(Me!Bsheetcostdraft![CSA/SAA]=0,0,Me!Bsheetcostdraft![CSA/SAA]/Me!Bsheetcostdraft![CSA/SAA])
-
When I look at what you have I am just lost since I can not tell and have no idea what the following names are used for (subform maybe?).
lsheetcostdraft
or
Bsheetcostdraft
Can anyone Help I am trying to use the expression builder to create an expression that returns a zero when a formula tries to divide by zero.
So far my attempts have failed.
This is what I have tried so far. I feel my logic is correct maybe my syntax is off.
Expr1: IIf(Bsheetcostdraft![CSA/SAA]=0,0,Icostcostdraft![CSA/SAA]/Bsheetcostdraft![CSA/SAA])
Can anyone guide me through this.
Never, Never, Never use the IIF() Function whenever there is even a remote possibility that a division by 0 could occur anywhere within the Expression. This Function will evaluate both the truepart and falsepart whether or not the truepart evaluates to True. This is 1 of the hugh pitfalls with the IIF() Function that was previously pointed out in a TheScripts Tip of the Week. A simple illustration will demonstrate this point: - dblNew = IIf(intY = 0, 0, intX/intY)
'This would seem harmless since you apparently covered your bases in the case where intY = 0 and you assumed the result would be 0. Unfortunately, if intY = 0, this statement will still cause a Runtime Error since the 2nd portion of the IIF expression will also be evaluated thus triggering a Division by 0 Error. Use the If...Then...Else statement in cases such as this NOT IIf(). Hope this helps.
Never, Never, Never use the IIF() Function whenever there is even a remote possibility that a division by 0 could occur anywhere within the Expression. This Function will evaluate both the truepart and falsepart whether or not the truepart evaluates to True. This is 1 of the hugh pitfalls with the IIF() Function that was previously pointed out in a TheScripts Tip of the Week. A simple illustration will demonstrate this point: - dblNew = IIf(intY = 0, 0, intX/intY)
'This would seem harmless since you apparently covered your bases in the case where intY = 0 and you assumed the result would be 0. Unfortunately, if intY = 0, this statement will still cause a Runtime Error since the 2nd portion of the IIF expression will also be evaluated thus triggering a Division by 0 Error. Use the If...Then...Else statement in cases such as this NOT IIf(). Hope this helps.
I tested this and I didn't get a runtime error. Works just fine.
I tested this and I didn't get a runtime error. Works just fine.
Just so everyone is aware I am not running vba code this is part of a select query that I am trying to run.
I tested this and I didn't get a runtime error. Works just fine.
It is only within the context of VBA Code, not SQL, that the Division by 0 - Error 11 will occur. I tested it several times and it does, in fact, generate this Error.
If your looking at a query in design view your select query statement should read: - MyNewFieldName:iif(tablename1.fieldnameofTable1=0,0,tablename1.fieldnameofTable1/tablename2.fieldnameofTable2)
ADezii I just wanted to say that for VBA purposes you are absolutely correct also it is much slower than the if then statement since it has to evaluate both parts.
If your looking at a query in design view your select query statement should read: - MyNewFieldName:iif(tablename1.fieldnameofTable1=0,0,tablename1.fieldnameofTable1/tablename2.fieldnameofTable2)
ADezii I just wanted to say that for VBA purposes you are absolutely correct also it is much slower than the if then statement since it has to evaluate both parts.
Yes I realize this but I am starting to think there is another problem let me explain. I am getting error message even when I am not dividing by zero. When I apply that formula. However when I take out the iif statement and just run it as simple division the formula will work unless I divide by zero. I think I am missing something more. Is there a possibility that this is a property error. I have all my fields set to except text. I dont know what else could be the problem.
fields set to except text
If the fields in question are not numeric fields then that could be your problem.
Guys the problem is solved I was an idiot and specified every field as text when it should have been number.
If your looking at a query in design view your select query statement should read: - MyNewFieldName:iif(tablename1.fieldnameofTable1=0,0,tablename1.fieldnameofTable1/tablename2.fieldnameofTable2)
ADezii I just wanted to say that for VBA purposes you are absolutely correct also it is much slower than the if then statement since it has to evaluate both parts.
BTW, the same type problems arise when dealing with the Choose() and Switch() Functions within the same context.
BTW, the same type problems arise when dealing with the Choose() and Switch() Functions within the same context.
I will remember this...
Glad you got it Mike
BTW, the same type problems arise when dealing with the Choose() and Switch() Functions within the same context.
I only tested in SQL as that is the only place I would use iif().
I only tested in SQL as that is the only place I would use iif().
Did you see the article I posted earlier about using it in a query? iif() and SQL
I posted more in this article than I wanted to so if someone wouldn't mind cleaning some of it out I just wanted the portion about the iif() statement...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wolfgang Kaml |
last post by:
Hello All,
I have been working on this for almost a week now and I haven't anything up
my sleeves anymore that I could test in addition or change....
Since I am not sure, if this is a Windows...
|
by: Yannick Turgeon |
last post by:
Hello,
We are in the process of examining our current main application. We have to
do some major changes and, in the process, are questionning/validating the
use of MS Access as front-end. The...
|
by: bettervssremoting |
last post by:
To view the full article, please visit
http://www.BetterVssRemoting.com
Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere
and VSS Remoting
This article makes a detailed...
|
by: Al the programmer |
last post by:
I need to access the serial ports on my webserver from an asp.net page. I
have no problem accessing the serial ports from a windows form application,
but the code doesn't work in asp.net. I have...
|
by: DaveG |
last post by:
Hi all
I am planning on writing a stock and accounts program for the family
business, I understand this is likely to take close to 2 years to
accomplish. The stock is likely to run into over a...
|
by: B1ackwater |
last post by:
We've fooled around with Access a bit, but only using the
single-user store-bought version. It seems to be a good
database - versatile and infinitely programmable - and
can apparently be used as a...
|
by: Mathieu Trentesaux |
last post by:
Hello
I downloaded Office 2007 for this reason :
It seems, once again, that it is impossible to save any modification
done in a VBA library, from the main project in Access.
The save button...
|
by: Bigpond News |
last post by:
Work at a large site - 1000+ PC's. Mixture of Win98 & WinXP. Majority of
applications using Access 97.
If I compile the Acc97 application on a Win98 PC, the .mde will run
perfectly on both...
|
by: surfrat_ |
last post by:
Hi,
I am having the following problems in getting Microsoft Visual Studio
2005 Professional to link to an Access .mdb
database. Please help me to sort this out.
Problem 1:
The Microsoft...
|
by: clintonG |
last post by:
To all Microsoft partners and customers who have been unable to download
recently or access ASP.NET documentation from the msdn2 website and for all
of those customers who have been lied to and...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |