stop Access from multipying a string that's not a number.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RZ15
    New Member
    • Jul 2007
    • 53

    stop Access from multipying a string that's not a number.

    Hi,

    I have a query and one of the fields in this query is as such:

    Total: [PURPRI]*[ORDQTY]-[DISCNT]

    The data type for the field [DISCNT] is a string (even though the field contains a number). For 10 out of the few thousand records, someone has entered in multiple spaces (ie: " ") in the fields. I don't know why they would do that, but it produces an error and when I export into excel, it exports it out without a total for those records. Is there a way I can tell Access to not subtract anything if [DISCNT] is not a number?

    Thanks in advance,

    Raza
  • RZ15
    New Member
    • Jul 2007
    • 53

    #2
    Oh yeah, and I don't have control over the database, it is located on a server and I don't have access to change anything. I can only pull data from it, so I can't go in and change the data type for the problem field.

    Comment

    • FishVal
      Recognized Expert Specialist
      • Jun 2007
      • 2656

      #3
      Hi, Raza.

      Not sure whether it will work if you run the query from Excel, but anyway try the following
      [PURPRI]*[ORDQTY]-Val([DISCNT])

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        Originally posted by RZ15
        Oh yeah, and I don't have control over the database, it is located on a server and I don't have access to change anything. I can only pull data from it, so I can't go in and change the data type for the problem field.
        Definitely a good point to add there Raza ;)
        BTW does your discount apply only the once per order as coded, or should it apply to each unit? If the latter then you will need to rearrange things somewhat as :
        Code:
        [ORDQTY] * ([PURPRI] - Val([DISCNT]))

        Comment

        • RZ15
          New Member
          • Jul 2007
          • 53

          #5
          Originally posted by NeoPa
          Definitely a good point to add there Raza ;)
          BTW does your discount apply only the once per order as coded, or should it apply to each unit? If the latter then you will need to rearrange things somewhat as :
          Code:
          [ORDQTY] * ([PURPRI] - Val([DISCNT]))
          Reading up on the Val() function, I believe this is what i need. Thank you for the help.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32636

            #6
            No problem.
            Glad I was able to.

            BTW - DID your formula need to apply discount per line?

            Comment

            • RZ15
              New Member
              • Jul 2007
              • 53

              #7
              You were right. I mapped this from an existing crystal report that was created before I got here into access and now that you mentioned it, it did look off. I assumed too much when I did that.

              The DISCNT is a percentage discount off the unit price. So now I have:

              Code:
              IIf(IsNull([DISCNT]), [PURPRI]*[ORDQTY], [PURPRI]*((100-Val([DISCNT]))/100)*[ORDQTY])

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32636

                #8
                Try instead :
                Code:
                [ORDQTY]*[PURPRI]*(100-Val(Nz([DISCNT],'0')))/100

                Comment

                • RZ15
                  New Member
                  • Jul 2007
                  • 53

                  #9
                  yes, that's good too. I suppose it is cleaner.

                  I actually never bothered to look up what Nz() actually does until now, though I knew it existed. I would just usually "IIF" my way out of the situation.

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32636

                    #10
                    In situations like this Nz() is much cleaner and easier to understand logic-wise.
                    Glad it helped anyway :)

                    Comment

                    Working...