calculating the sum of a field in using access forms.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mazenblue
    New Member
    • Sep 2007
    • 3

    calculating the sum of a field in using access forms.

    Dear All
    i have the following problem and i am using microsoft access 2000 forms:-
    i am working on a system for a store, and i have a table named orders (order id , order_date , order_price, order_company_o wner_name), and i have created a form for this table , what i am trying to do is that i want to add a field that calculate the sum of the prices for all the retrived orders (order_price) column for all the orders on the form that will be retrived after filtering the records (records - filter - filter by form) and i want the sum of those records to be calculted once the user click on the calculate button ?
    thanks in advance
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by mazenblue
    Dear All
    i have the following problem and i am using microsoft access 2000 forms:-
    i am working on a system for a store, and i have a table named orders (order id , order_date , order_price, order_company_o wner_name), and i have created a form for this table , what i am trying to do is that i want to add a field that calculate the sum of the prices for all the retrived orders (order_price) column for all the orders on the form that will be retrived after filtering the records (records - filter - filter by form) and i want the sum of those records to be calculted once the user click on the calculate button ?
    thanks in advance
    Use the DSum function over your filtered domain:

    DSum("[order_price]", "YourFilteredQu ery")

    Or use DSum with where clause (see example below)

    DSum("[order_price]", "YourBaseQuery" , "order_date < Xdate")

    Comment

    • lee123
      Contributor
      • Feb 2007
      • 556

      #3
      on the footer of the form add a text box in design view go to the properties of the text box find the controlsource and put this in the controlsource:

      =sum(orderprice )

      lee123

      Comment

      • mazenblue
        New Member
        • Sep 2007
        • 3

        #4
        Originally posted by lee123
        on the footer of the form add a text box in design view go to the properties of the text box find the controlsource and put this in the controlsource:

        =sum(orderprice )

        lee123
        Many thnaks it works well , but i need to calculate the sum only when the user clicks on a button, not automatically.

        Comment

        • mazenblue
          New Member
          • Sep 2007
          • 3

          #5
          any advice on how to calculate the sum of the prices only when i press on the calculate button???

          Comment

          • puppydogbuddy
            Recognized Expert Top Contributor
            • May 2007
            • 1923

            #6
            Originally posted by mazenblue
            any advice on how to calculate the sum of the prices only when i press on the calculate button???

            Here is one way that might work:
            1. Set the visible property of the textbox with the calc to no in the forms current event.
            2. Make it visible when you click the button:

            Code:
            Private Sub YourButton_Click()
            Me.YourTextbox.Visible = True
            End Sub
            
            Private Sub Form_Current()
            Me.YourTextbox.Visible = False
            End Sub

            Comment

            • puppydogbuddy
              Recognized Expert Top Contributor
              • May 2007
              • 1923

              #7
              If you don;t want the calc to occur, visible or not, substitute enabled for visible in the above code.

              Comment

              Working...