• Null problem (XP/2K)

    Author
    Topic
    #390099

    I have the following line of code:

    !curFixedAmount = Me.curPriceShekF + Me.curPriceShekM + (fGetYatzig() * Me.curPriceDollF) + (fGetYatzig() * Me.curPriceDollM)

    the me.* are unbound text boxes that can be null.
    the function fgetyatzig gets the exchange rate from NIs to $ from a table.
    If one of the text boxes is blank then I get the following error:
    “Run time error 13 type mismatch”

    How can I use the NZ function to get rid of this ? I have tried to use it and it does not help.
    Any ideas??
    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #691658

      You probably need to wrap each occurence in NZ()

      !curFixedAmount = NZ(Me.curPriceShekF) + NZ(Me.curPriceShekM) + (fGetYatzig() * NZ(Me.curPriceDollF)) + (fGetYatzig() * NZ(Me.curPriceDollM))

      HTH

      Peter

      • #691659

        I had tried and it did not help, but to be sure I tried what you had written and that also did not work.
        thanks for the try.

        • #691662

          Does this work? It is almost the same as Peter’s solution, but explicitly sets the value to be used instead of Null.

          !curFixedAmount = NZ(Me.curPriceShekF, 0) + NZ(Me.curPriceShekM, 0) + (fGetYatzig() * NZ(Me.curPriceDollF, 0)) + (fGetYatzig() * NZ(Me.curPriceDollM, 0))

          • #691664

            I am about to leave the office. I will try this later
            Thanks Hans

          • #691780

            Still the same problem.
            Could it be the field in the original table which is currency cannot deal with this? (Although I cannot think of any reason why!)
            Thanks

            • #691814

              OK, one more thing to try:

              !curFixedAmount = CCur(NZ(Me.curPriceShekF, 0)) + CCur(NZ(Me.curPriceShekM, 0)) + fGetYatzig() * CCur(NZ(Me.curPriceDollF, 0)) + fGetYatzig() * CCur(NZ(Me.curPriceDollM, 0))

            • #691958

              YES!!!
              thanks Hans.
              What I learn from this is that each part of the function needs a ccur, and not a general one around the whole expression. Why?

            • #691961

              The reason is that if any component of the expression equates to Null then the whole expression equates to Null.

            • #691964

              that explains why each part needs a NZ, but why can you not put a CCur around the whole expression?

            • #691966

              I don’t know the explanation for sure, but sometimes NZ results in a string, even if you would expect a numeric result. If that is the case in your database, CCur forces the result to currency.

    Viewing 0 reply threads
    Reply To: Null problem (XP/2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: