A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"Division by zero", but...



 
 
Thread Tools Display Modes
  #1  
Old July 2nd, 2007, 10:48 PM posted to microsoft.public.access.queries
rachael
external usenet poster
 
Posts: 78
Default "Division by zero", but...

I have a UNION query that's merging the results of several individual
queries. When I run the UNION, i briefly see the results of the query as
expected. A few seconds later, i get a "Division by zero" error, and all
fields go to #Name? errors.

But, when i run the individual queries that are used in the UNION, i don't
get *any* "Division by zero" errors. What's going on???

rachael
  #2  
Old July 3rd, 2007, 01:55 AM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default "Division by zero", but...

One possibility is that Access is struggling to identify the data type.

JET uses the results from the first SELECT to identify the data type for the
column. If the first SELECT returned Null or integer values in all records,
that would determine the data type of the column (which could end up as
binary or an integer type.) The subsequent SELECTs could then be rounded,
and after rounding you could get a division by zero that did not occur in
any of the individual SELECTs.

If that is the cause, you might be able to solve it by re-ordering the
SELECTs, or by typecasting the calcuation. You can even use an expression
like this:
IIf(False, 0.5, [Field1] / [Field2])
Of course, False is never true, so it never returns the 0.5, but it's enough
to give JET a clue as to the data type to use if Field1 / Field2 returns
Null in all records.

(Of couse, you also want handle the case where Field2 is zero.)

If the query calls a VBA function, there are other possible causes of the
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"rachael" wrote in message
...
I have a UNION query that's merging the results of several individual
queries. When I run the UNION, i briefly see the results of the query as
expected. A few seconds later, i get a "Division by zero" error, and all
fields go to #Name? errors.

But, when i run the individual queries that are used in the UNION, i don't
get *any* "Division by zero" errors. What's going on???

rachael


  #3  
Old July 3rd, 2007, 11:20 AM posted to microsoft.public.access.queries
DAVID
external usenet poster
 
Posts: 54
Default "Division by zero", but...

I think that you only get that behaviour when
one invalid row invalidates all rows.

Are you using a UNION query or a UNION ALL query?

Try with UNION ALL to see if you can identify
the row(s) which cause the query to fail.

(david)



rachael wrote:
I have a UNION query that's merging the results of several individual
queries. When I run the UNION, i briefly see the results of the query as
expected. A few seconds later, i get a "Division by zero" error, and all
fields go to #Name? errors.

But, when i run the individual queries that are used in the UNION, i don't
get *any* "Division by zero" errors. What's going on???

rachael

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:22 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.