Results 1 to 8 of 8
  1. #1
    Kat2016 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    14

    Query overflow error

    Hi,



    I have a calculated field in my query that uses division. It is giving me an overflow error because I am dividing by zero in some entries.

    My SQL is:

    SELECT [Adjust Casino Retailers Activity 2016].activity_date, Sum([Adjust Casino Retailers Activity 2016].cash_played) AS SumOfcash_played, Sum([Adjust Casino Retailers Activity 2016].cash_won) AS SumOfcash_won, Sum([Adjust Casino Retailers Activity 2016].hand_pays) AS SumOfhand_pays, Sum([Adjust Casino Retailers Activity 2016].progressive_increment) AS SumOfprogressive_increment, Sum([Adjust Casino Retailers Activity 2016].net_sales) AS SumOfnet_sales, [Adjust Casino Retailers Activity 2016].WIN, Sum([Adjust Casino Retailers Activity 2016].[Due to AGLC]) AS [SumOfDue to AGLC], Sum([Adjust Casino Retailers Activity 2016].Commission) AS SumOfCommissionFROM [Adjust Casino Retailers Activity 2016]
    GROUP BY [Adjust Casino Retailers Activity 2016].activity_date, [Adjust Casino Retailers Activity 2016].WIN;

    I think I have to include somewhere in it that it should ignore entries that would be divided by zero, but I have no idea where to begin.

    I am extremely new to Access, and would greatly appreciate if someone could help me out.

    Thanks.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    suggest as a priority learn to use aliasing or shorter names, will make your code much easier to read - see table properties in query builder

    SELECT A.activity_date, Sum(A.cash_played) AS SumOfcash_played, Sum(A.cash_won) AS SumOfcash_won, Sum(A.hand_pays) AS SumOfhand_pays, Sum(A.progressive_increment) AS SumOfprogressive_increment, Sum(A.net_sales) AS SumOfnet_sales, A.WIN, Sum(A.[Due to AGLC]) AS [SumOfDue to AGLC], Sum(A.Commission) AS SumOfCommission FROM [Adjust Casino Retailers Activity 2016] AS A
    GROUP BY A.activity_date, A.WIN;

    You say you are dividing by zero but I don't see any divisions in what you have provided

    the way to protect against division by zero errors is to use an iif statement

    somevalue:iif(thisnum=0, 0, thatnum/thisnum)

    you may also need to protect against nulls in which case

    somevalue:iif(nz(thisnum,0)=0, 0, thatnum/thisnum)

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    one other thought - overflows usually mean trying to assign a bigger number to a smaller data type - integer for example covers whole numbers from -32767 to +32767 - so if you calculate a value outside this range say 40000 and assign it to the integer field it will overflow - the solutio is to change your number type from integer to long

  4. #4
    Kat2016 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    14
    I will suggest that to the lady I am helping.

    WIN is a calculated field from my database. When I try to run a summarized query it gives me an overflow error. WIN entries usually are 0.5 - 1.9. I'm assuming that is where the issue originates.

    Where exactly will the iff statement be entered into the SQL?

    What does it mean by thisnumb or thatnumb? Must I replace those with specific numbers?

    I'm sorry I am very new to this.

  5. #5
    Kat2016 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    14
    The calculation used for WIN is ( [cash_won] + [hand_pays] ) / [cash_played]

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    so the iif statement would look like this

    iif([cash_played]=0,0,( [cash_won] + [hand_pays] ) / [cash_played])

    note calculated fields in tables are not considered a good idea by many professionals, they can generate all sorts of unexpected problems - see this link

    http://allenbrowne.com/casu-14.html

  7. #7
    Kat2016 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    14
    Thank you so much

    One last question. Can that same thing be done to a summary query?

  8. #8
    Kat2016 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    14
    Actually scrap that question I got it.
    Once again thank you, you have saved my very existence.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Overflow Error
    By jtm013 in forum Programming
    Replies: 15
    Last Post: 01-07-2015, 01:01 PM
  2. Overflow Error
    By pj33558 in forum Reports
    Replies: 1
    Last Post: 06-19-2014, 10:50 AM
  3. Overflow Error
    By mike02 in forum Programming
    Replies: 14
    Last Post: 07-12-2013, 10:53 AM
  4. OVERFLOW error in both Query and Report
    By LanieB in forum Access
    Replies: 9
    Last Post: 11-11-2011, 08:54 PM
  5. Overflow error - change field type in query?
    By Lady_Jane in forum Queries
    Replies: 6
    Last Post: 05-25-2011, 01:10 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums