Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Glad you found a solution. It occurs to me that the expression could error if DailyincreaseGB is 0 because with an IIf all terms of the expression must be able to be evaluated, even if it is not the term that returns the value. Handle the possibility of division by 0 with an IIf to provide an alternate value, in this example Null:

    IIf([DailyincreaseGB]=0,'No Change',IIf([DailyincreaseGB]>0,'Decrease Of Used',Int(Round(LFAS02Aggr3DateComparison.LastFree GB/IIf(DailyIncreaseGB=0,Null,DailyIncreaseGB),1)))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Could you explain this please?

    From what I know, which clearly isn't a hell of a lot ,
    Code:
     IIf([DailyincreaseGB]=0,'No Change'
    would surely stop it getting anywhere near to this point
    Code:
     IIf(DailyIncreaseGB=0,Null
    ??

    I don't understand how it could error if DailyIncreaseGB is '0'; surely that would be captured in the first part and return 'No Change'??

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Because ALL parts of an IIf are calculated. As stated, every term in the IIf must be able to be evaluated, even if it is not the part that returns value. Division by 0 will error so that term causes the entire expression to error.

    You can test this in the Immediate Window of the VBA editor. Paste the following into the window and press Enter (with cursor at end of line).

    ?IIf(1=1,"Yes",1/1)

    then do the same with

    ?IIf(1=1,"Yes",1/0)

    What happens?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #19
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    I get an error .... But I still don't fully understand. I don't know why it would ever divide by 0, if all possible circumstances have been covered (i.e. 1) Is it equal to 0? 2) Is it Bigger than 0? 3) Is it Less than 0?)

    I'm not saying you're wrong, clearly you are not! I just would like to understand why this is the case, for future reference. Perhaps it's the below part i'm just not grasping??

    Because ALL parts of an IIf are calculated. As stated, every term in the IIf must be able to be evaluated, even if it is not the part that returns value

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That's just the nature of the IIf function. Every equation in the statement will calculate and therefore must be a valid expression. If any part fails it all fails. Division by 0 is not valid so it throws error. I'm not the architect of VBA, I just use it and so must accept the fact and work around it.

    If your data (raw or calculated DailyIncreaseGB) will never have a 0 value then no issue, however, it seems that 0 is getting sent to the IIf (that's why you have an =0 condition) and that is an issue to be dealt with.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 03-05-2012, 10:20 AM
  2. SQL Correct Syntax
    By tbassngal in forum Queries
    Replies: 11
    Last Post: 09-01-2011, 01:55 PM
  3. Correct Formatting of SQL in VBA?
    By Coffee in forum Queries
    Replies: 6
    Last Post: 08-04-2011, 12:03 AM
  4. Help with getting correct set of records
    By cvegas in forum Queries
    Replies: 3
    Last Post: 07-29-2011, 08:47 AM
  5. Replies: 9
    Last Post: 06-26-2011, 09:14 PM

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