How To Calculate percentages in Access???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AZKing
    New Member
    • Sep 2006
    • 12

    How To Calculate percentages in Access???

    Hi all,

    I would like to know how do you go about calculating percentages in Access.

    For example, in a form I have 3 combo boxes with drop down menus where a user can select "Yes" or "No" and a text box where I will calculate a percentage. What I am looking for is something like this:
    If combo1 = "yes" then percentagebox = 1 / 3 * 100
    ElseIf combo1 AND combo2 = "Yes" then percentagebox = 2 / 3 * 100
    ElseIf combo1 AND combo2 AND combo3 = "Yes" then percentagebox = 3 / 3 * 100.

    Can anyone tell me how can I go about creating and calculating percentages such as this in Access? I appreciate any help.

    Thanks
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    I think you need to tell us a little bit more about exactly what you're trying to accomplish, AZKing. I have to tell you, what you've posted so far sounds as if you're trying to swat a fly with an atom bomb!

    Comment

    • AZKing
      New Member
      • Sep 2006
      • 12

      #3
      Ok, I am trying to do the following:

      In a form in Access, I have 3 drop down menus where you can select "yes" or "no". I also have a text box where I would like a percentage to show up based on the answers of the 3 drop down menus. For example, if in drop down menu 1 "yes" is selected, I would like 33.3 % to show up in the text box. If in drop down menus 1 and 2 "yes" is selected, I would like 66.7 % to show up in the text box. If in drop down menu 1, 2, and 3 "yes" is selected, I would like 100 % to show up in the text box.

      Is this a little more clear?

      I would appreciate any help. Thanks.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by AZKing
        Hi all,

        I would like to know how do you go about calculating percentages in Access.

        For example, in a form I have 3 combo boxes with drop down menus where a user can select "Yes" or "No" and a text box where I will calculate a percentage. What I am looking for is something like this:
        If combo1 = "yes" then percentagebox = 1 / 3 * 100
        ElseIf combo1 AND combo2 = "Yes" then percentagebox = 2 / 3 * 100
        ElseIf combo1 AND combo2 AND combo3 = "Yes" then percentagebox = 3 / 3 * 100.

        Can anyone tell me how can I go about creating and calculating percentages such as this in Access? I appreciate any help.

        Thanks
        I think what you are looking for is the Format() Function in which an Expression can be properly formatted to produce a Percentage as in:
        Code:
        Format$(1/4,"Percent") ==> 25.00%

        Comment

        • AZKing
          New Member
          • Sep 2006
          • 12

          #5
          Originally posted by ADezii
          I think what you are looking for is the Format() Function in which an Expression can be properly formatted to produce a Percentage as in:
          Code:
          Format$(1/4,"Percent") ==> 25.00%

          Hi, I'm not sure I understand, can you please give me an example?

          Thanks.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32636

            #6
            What happens if Combo2 is selected on its own?
            Your question is not very clear in this respect. What is the idea behind this? That may help to understand where you're coming from.
            What do you have on your form at the moment? :confused:

            Comment

            • AZKing
              New Member
              • Sep 2006
              • 12

              #7
              Originally posted by NeoPa
              What happens if Combo2 is selected on its own?
              Your question is not very clear in this respect. What is the idea behind this? That may help to understand where you're coming from.
              What do you have on your form at the moment? :confused:
              Well, I'm gonna freeze or make not visible combo2 and combo3 if combo1 is not selected, same with combo3, I will freeze it or make it not visible if both combo1 and combo2 are not selected, which will remove the possibility of this occuring.
              The idea behind this is to calculate the percentage of work completed. So if combo1 is selected as completed, than the percentage should be 33.3 %; if combo1 and combo2 are selected as completed, than the percentage should be 66.7 %; and if combo1, combo2, and combo3 are selected as completed, than the percentage should read 100 %. I hope this is a little more clear.

              Any suggestions?

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32636

                #8
                This code will show the percentage required but as text.
                Code:
                Private Sub Combo1_AfterUpdate()
                    Call TextSource
                End Sub
                
                Private Sub Combo2_AfterUpdate()
                    Call TextSource
                End Sub
                
                Private Sub Combo3_AfterUpdate()
                    Call TextSource
                End Sub
                
                Private Sub TextSource()
                    If Me!Combo3 = "Completed" Then
                        Me!percentagebox = "100.0%"
                    Elseif Me!Combo2 = "Completed" Then
                        Me!percentagebox = " 66.7%"
                    Elseif Me!Combo1 = "Completed" Then
                        Me!percentagebox = " 33.3%"
                    Else
                        Me!percentagebox = "  0.0%"
                    End If
                End Sub
                If you already have code (I suspect you do) in the AfterUpdate event procedures of your ComboBoxes then just incorporate this call into it.

                Comment

                • AZKing
                  New Member
                  • Sep 2006
                  • 12

                  #9
                  Originally posted by NeoPa
                  This code will show the percentage required but as text.
                  Code:
                  Private Sub Combo1_AfterUpdate()
                      Call TextSource
                  End Sub
                  
                  Private Sub Combo2_AfterUpdate()
                      Call TextSource
                  End Sub
                  
                  Private Sub Combo3_AfterUpdate()
                      Call TextSource
                  End Sub
                  
                  Private Sub TextSource()
                      If Me!Combo3 = "Completed" Then
                          Me!percentagebox = "100.0%"
                      Elseif Me!Combo2 = "Completed" Then
                          Me!percentagebox = " 66.7%"
                      Elseif Me!Combo1 = "Completed" Then
                          Me!percentagebox = " 33.3%"
                      Else
                          Me!percentagebox = "  0.0%"
                      End If
                  End Sub
                  If you already have code (I suspect you do) in the AfterUpdate event procedures of your ComboBoxes then just incorporate this call into it.
                  Thank you very much, it worked great!!! I was very close myself, I just couldn't get it to work properly. I appreciate your help and input and thanks again :)

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32636

                    #10
                    Glad I could help.
                    Hopefully you see the concept and that's now something you'll be able to do in future :)

                    Comment

                    Working...