Automating Access form to remove tax when tax "yes/no" field is unchecked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mulchgirl
    New Member
    • Apr 2008
    • 27

    Automating Access form to remove tax when tax "yes/no" field is unchecked

    I've been using Access for awhile, although not very familiar with VB. I am designing an order form that automatically calculates tax on the products ordered. On the form and in the underlying table, I have a yes/no field to check if the customer is taxable. I would like the expression I built to calculate tax on the form, to =0 if the yes/no field is unchecked, meaning the customer is nontaxable. Any simple way to do this?
    Thanks for any help
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Not really sure if all of your control names and field names.
    However the basic would be to use an IIF() in an unbound field.
    It will also vary a tad base on the structure of your form

    So in the unbound control, in the recordsource property, you'd build your formula. Here's a link to the IIF:
    IIf Function

    Give-it-whirl, see what you come up with... if you get stuck post back and we'll have a go at it from there!
    You can also check out the insight articles

    Comment

    • mulchgirl
      New Member
      • Apr 2008
      • 27

      #3
      I think I understand, except, the control I am trying to make either show the calculated tax or not, is a calculation. =([qryOrderDetails Extended subform]![Order Subtotal])*0.06 - it's subtotaling the entended prices and multiplying them by our tax rate, and when I put that calculation in as my positive to if my [taxable] field is yes, I just get ######### in my field on my form. But when I put $0.00 in as my negative, it does work - so I'm not sure if it is still doing the calculation or not.
      Thanks again

      Comment

      • mulchgirl
        New Member
        • Apr 2008
        • 27

        #4
        I should have said that I do have $0.00 in as my false part and when I uncheck the customer's tax status, it does say $0.00, it's just when I check the status as taxable, I get the ######

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          If you are just getting ########, then that just means that your control isn't big enough to display your data. You just need to make your control wider.

          Comment

          • mulchgirl
            New Member
            • Apr 2008
            • 27

            #6
            Thanks Seth, but I had tried adjusting the control size earlier and got the same. The total should be only over $1000.00 and I have the decimal spaces set to 2 - I'm thinking it's got to be in my code.

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              @mulchgirl:
              For a temporary check...
              Please go back in to the design mode of the form.
              Please double the width of the control that has the calculation.
              You do not need to save it at this point...
              Switch from design to form view.
              Hopefully you will see the expected result.


              @All:
              We've started branching on this thread from the original question; however because we haven't yet verified the calculation's result due to the formatting issue, I think it's allowable.
              Once mulchgirl has verified the results, the formatting question should be started in a new thread, with reference to this thread if the information is needed for clarity.

              Comment

              • mulchgirl
                New Member
                • Apr 2008
                • 27

                #8
                zmbd - sorry if I am causing an issue - I expanded the width and what shows in the control is not an answer to my calculation, but just the calculation.... .. =([qryOrderDetails Extended subform]![Order Subtotal])*0.06. Do I need to add something to my IIf statment to have it calculate? Thanks so much.

                Comment

                • zmbd
                  Recognized Expert Moderator Expert
                  • Mar 2012
                  • 5501

                  #9
                  If you are still in design view, that is expected; hoewever, if you are in Form view then we have an issue with how the formula was entered into the control.

                  Please confirm what you saw in the Form view.

                  Comment

                  • mulchgirl
                    New Member
                    • Apr 2008
                    • 27

                    #10
                    When I am in form view, it shows the calculation: ([qryOrderDetails Extended subform]!]Order Subtotal])*0.06 in the control - exactly what I typed in the control in the design view, in the truepart of the IIf function. To help explain more, In my Orders table, I have a field named "Taxable", it's data type is yes/no. I added this field to an "Orders" form (this is based on a query that combines the Orders table and Order Details table). On this form I have a a control that calculates the totals of all the products for the one order (which is the above calculation). My goal is to have a control that calculates tax of 6% on the total fo the products if the customer is taxable. I hope my expanation helps, and doesn't just show how little I understand ;)

                    Comment

                    • Seth Schrock
                      Recognized Expert Specialist
                      • Dec 2010
                      • 2965

                      #11
                      While in design view, you need to enter an equals sign (=) before your calculation.

                      Comment

                      • mulchgirl
                        New Member
                        • Apr 2008
                        • 27

                        #12
                        Seth, I tried adding the = sign before the equation and after the ", in the truepart, and it still shows only the equation itself, not a result of the calculation.

                        Comment

                        • Seth Schrock
                          Recognized Expert Specialist
                          • Dec 2010
                          • 2965

                          #13
                          I'm not seeing the " in your equation, so I'll how the equation should be put into the textbox in design view:
                          Code:
                          =([qryOrderDetailsExtended subform]!]Order Subtotal])*0.06

                          Comment

                          • mulchgirl
                            New Member
                            • Apr 2008
                            • 27

                            #14
                            Yeah, sorry - the " " were for around my equation in the true part of my IIf statement. My Iff statement now looks like this:
                            Code:
                            =IIf([Taxable]=Yes, "=[qryOrderDetailsExtended subform]![Order Subtotal]*.06)","$0.00")
                            . I am getting the result of $0.00 if I uncheck my taxable box (which is what I want), but if my taxable box is checked, all that shows in my control in the form view is =[qryOrderDetails Extended subform]![Order Subtotal]*.06" - Thanks for all your help!
                            Last edited by zmbd; Feb 25 '13, 03:28 PM. Reason: [z{please, either click the [Code/] button in the format-bar first and post code between the tags, or highlight the code and then click [CODE/].}]

                            Comment

                            • zmbd
                              Recognized Expert Moderator Expert
                              • Mar 2012
                              • 5501

                              #15
                              Remove the inner double quotes.
                              Code:
                              =IIf([Taxable]=Yes, ([qryOrderDetailsExtended subform]![Order Subtotal]*.06),"$0.00")

                              Comment

                              Working...