iif statement in a default value not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hannoudw
    New Member
    • Aug 2010
    • 115

    iif statement in a default value not working

    Hi I'm working on the invoice customer form
    and i had those text box :
    txtarticle, txtPrice, txtAfterDiscPri ce, txtCashMoney
    i want to write this code
    Code:
    If (txtAfterDiscPrice is null) then txtCashMoney=txtPrice ;
    else 
    txtCashMoney=txtAfterDiscPrice;
    on the default value of the txtCashMoney.
    so i wrote this on the default value of the txtCashMoney:
    Code:
    = iif(isnull(txtAfterDiscPrice ) ,= [txtPrice] ,= [txtAfterDiscPrice ]
    but it's not working does anyone know why ?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    If the names and references are right then you could try :
    Code:
    =Nz([txtAfterDiscPrice],[txtPrice])

    Comment

    • colintis
      Contributor
      • Mar 2010
      • 255

      #3
      The problem I see in this line of code would be the formating. In true / false criteria you don't need the "=", try that again with the "=" removed:

      Code:
      [txtCashMoney]= iif(isnull([txtAfterDiscPrice] ,[txtPrice] ,[txtAfterDiscPrice])
      Last edited by colintis; Aug 6 '10, 01:02 AM. Reason: Correction with missing brackets

      Comment

      • Jerry Maiapu
        Contributor
        • Feb 2010
        • 259

        #4
        Colintis,
        Closing brackets is missing and a few corrections.. Though this is a replica of Post#2. For correction sake..

        Code:
        = IIf(IsNull([B][[/B]txtAfterDiscPrice[B]][/B]) ,[txtPrice] ,[txtAfterDiscPrice[B]][/B][B])[/B]

        Comment

        • colintis
          Contributor
          • Mar 2010
          • 255

          #5
          Oops...Thanks for that one Jerry :P

          Comment

          • hannoudw
            New Member
            • Aug 2010
            • 115

            #6
            Well i tried this one it wont give me errors but nothing happened the field CashMoney still empty :(
            maybe i should do this with an event like jim told me

            Comment

            • Jerry Maiapu
              Contributor
              • Feb 2010
              • 259

              #7
              Take note that if txtPrice or txtAfterDiscPri ce have null/no values then you might see empty space in CashMoney field. Apart from this I am sure that NZ and IIf..IsNull functions of the previous posts should work perfectly.

              Just like you proposed .
              Try this on the On_Current event of the form.

              Code:
              If IsNull(txtAfterDiscPrice) then
              me.txtCashMoney=txtPrice  
              else  
              me.txtCashMoney=txtAfterDiscPrice
              end if

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32662

                #8
                You say you've "tried this one", but there are three suggestions you could be referring to. I have no idea what you have and haven't tried so I am not in a position to help at this time.

                Comment

                Working...