Results 1 to 10 of 10
  1. #1
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281

    IIf Formula returning wrong result and thus a false error

    Greetings Everyone...

    Not sure why this IIf is calculating the 'False' part

    Here is how it is written:



    Code:
    PctSavings = IIf(Me.CmbDept = "Store Discount", 1, (TtlSavings / Me.TxtRegPriceTtl))
    Me.CmbDept does equal "Store Discount" and thus I'm looking for the return of 100% in the PctSavings control and the subsequent table field name
    however the formula is blowing past the True part and calculating the false part and giving a Div/0 Error. (The values of TtlSavings & Me.TxtRegPriceTtl are $7.50 and 0 respectively)

    Looking forward to reading is staring me right in the face but I'm just too blind to see it...

    Thank You All ~

    RT91
    Last edited by RunTime91; 03-14-2023 at 04:16 PM.

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    Are the Data Types of TtlSavings = Currency and TxtRegPriceTtl = Numeric ?


    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Could it be that the combo is displaying "Store Discount" but the actual bound column is hidden and maybe has a different value (numeric ID usually)?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,911
    Quote Originally Posted by RunTime91 View Post
    Greetings Everyone...

    Not sure why this IIf is calculating the 'False' part

    Here is how it is written:

    [code]
    PctSavings = IIf(Me.CmbDept = "Store Discount", 1, (TtlSavings / Me.TxtRegPriceTtl))

    Me.CmbDept does equal "Store Discount" and thus I'm looking for the return of 100% in the PctSavings control and the subsequent table field name
    however the formula is blowing past the True part and calculating the false part and giving a Div/0 Error. (The values of TtlSavings & Me.TxtRegPriceTtl are $7.50 and 0 respectively)

    Looking forward to reading is staring me right in the face but I'm just too blind to see it...

    Thank You All ~

    RT91
    Is CmbDept a lookup field?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Not sure why this IIf is calculating the 'False' part
    All parts of that function are evaluated. It does not stop just because the first one might be true.
    EDIT - I didn't post that as a solution but to let you know that both parts are evaluated because it seems you didn't realize that. Have to say though, I've never really understood the significance of it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281
    Hey Mike ~

    Checked and both controls are set to Currency - 2 decimals.

  7. #7
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281
    Hey Gicu...

    I'm using a single field table for the row source on that particular combo. the bound column is set to 1 if I set it to 0 I get the numeric ID you mentioned)
    When I step through the code and hover over the CmbDept it gives back "Store Discount" so (I think) that is good to go.

  8. #8
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281
    Welshgasman ~

    I'm gonna let you educate me on this one.

    I believe the answer is no...

    The ComboBox is populated using a query with a single table as the source.

    My understanding of a lookup field is different than that... but I'm light on knowledge with that so if I'm wrong I'm ready to learn.

  9. #9
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281
    Hey Micron ~

    You are correct Sir ~ That! ~ I did not know...I'm not understanding that either.

    Now that I know that however, I think I am going to re-think my approach to that section of code.

    I'll try a different approach and post back

    Thanks my Brother!

  10. #10
    RunTime91 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2014
    Posts
    281
    Solved ~

    To everyone who chimed in on this one ~ Thank You!

    As it turns out adding the Column did the trick.

    Code:
    PctSavings = IIf(Me.CmbDept.Column(0) = "Store Discount", 1, (TtlSavings / Me.TxtRegPriceTtl))
    Thanks Again to everyone!!

    RT91

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

Similar Threads

  1. Replies: 7
    Last Post: 11-03-2018, 02:31 PM
  2. Replies: 6
    Last Post: 09-26-2016, 10:36 PM
  3. Error Message Result In Count Formula
    By EHittner in forum Forms
    Replies: 4
    Last Post: 10-22-2013, 10:52 AM
  4. related to false result while filtering form
    By ritimajain in forum Forms
    Replies: 15
    Last Post: 08-11-2013, 10:31 PM
  5. Replies: 7
    Last Post: 01-11-2012, 12:24 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