473,387 Members | 1,597 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,387 software developers and data experts.

Access Problem

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.
Mar 21 '07 #1
17 1665
Rabbit
12,516 Expert Mod 8TB
Have you tried '.' instead of '!'? Also I think you made a typo with lcostcostdraft, should probably be lsheetcostdraft?
Mar 21 '07 #2
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.
Mar 21 '07 #3
Rabbit
12,516 Expert Mod 8TB
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.
Mar 21 '07 #4
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.
Mar 21 '07 #5
Denburt
1,356 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. IIf(Me!Bsheetcostdraft![CSA/SAA]=0,0,Me!Bsheetcostdraft![CSA/SAA]/Me!Bsheetcostdraft![CSA/SAA])
  2.  
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
Mar 21 '07 #6
ADezii
8,834 Expert 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 22 '07 #7
Rabbit
12,516 Expert Mod 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 22 '07 #8
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.
Mar 22 '07 #9
ADezii
8,834 Expert 8TB
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.
Mar 22 '07 #10
Denburt
1,356 Expert 1GB
If your looking at a query in design view your select query statement should read:
Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 22 '07 #11
If your looking at a query in design view your select query statement should read:
Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 22 '07 #12
Denburt
1,356 Expert 1GB
fields set to except text
If the fields in question are not numeric fields then that could be your problem.
Mar 22 '07 #13
Guys the problem is solved I was an idiot and specified every field as text when it should have been number.
Mar 22 '07 #14
ADezii
8,834 Expert 8TB
If your looking at a query in design view your select query statement should read:
Expand|Select|Wrap|Line Numbers
  1. 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.
Mar 22 '07 #15
Denburt
1,356 Expert 1GB
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
Mar 22 '07 #16
Rabbit
12,516 Expert Mod 8TB
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().
Mar 23 '07 #17
Denburt
1,356 Expert 1GB
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...
Mar 23 '07 #18

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

Similar topics

11
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...
49
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...
0
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...
13
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...
17
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...
5
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...
34
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...
21
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...
18
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...
7
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...
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: 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$) { } ...
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
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:
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
marktang
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,...

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.