Check box problem...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hrprabhu
    New Member
    • May 2010
    • 83

    Check box problem...

    Hi All,

    Code:
    Private Sub chkAddToTaxZone_AfterUpdate()
        If chkAddToTaxZone Then
            Me.NoOfDays = NoOfDays
            Me.FNTotal = FNTotal
        Else
            Me.NoOfDays = (-1) * NoOfDays
            Me.FNTotal = (-1) * FNTotal
        End If
        Me.Requery
    End Sub
    I have a small database. In the form I have a check box called chkAddToTaxZone . I set the default value -1.

    Basically I want it to change the value of two calculated fields from positive to negative when the check box value is 0.

    When I check the value again, the values in these two calculated field does not change. I have to do it a few things.

    What am I missing?

    Raghu
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    I'm not 100% sure what the items on the right side of the equal sign resolves to, but I'm guessing it is the same as what is on the left side. So the Textbox is being set to itself or set to itself times -1.
    If this is the case, the way it is written, the sign will only change when the Checkbox is not ticked and it will leave the values alone when the Checkbox changes from unchecked to checked.
    Changing the code to just the following will probably fix it:
    Code:
        Me.NoOfDays = (-1) * NoOfDays
        Me.FNTotal = (-1) * FNTotal
        Me.Requery

    Comment

    • hrprabhu
      New Member
      • May 2010
      • 83

      #3
      jforbes,

      Thank you very much!

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Raghu.

        Imagine you have already cleared the CheckBox and set the values to negative.
        1. Do you want them to be set back to positive when the CheckBox is set again?
        2. Do you want them to be set back to positive when the CheckBox is cleared again after being set?
        3. Do you want them to stay negative forever?

        Comment

        • hrprabhu
          New Member
          • May 2010
          • 83

          #5
          Hi NeoPa

          Basically toogle the values. If the check box is ticked, then the value should be positive if not negative.

          Thanks for your time. Though I have been using Access since 1993, I did not start VBA till recently. Hence I am paying the price.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            In that case JForbes' post #2 will suit you perfectly I think.

            VBA is fun. Once you get into it i'm sure you'll be pleased you did and find you enjoy working with it :-)

            Comment

            • hrprabhu
              New Member
              • May 2010
              • 83

              #7
              Thanks...Neopa Will try

              Comment

              • hrprabhu
                New Member
                • May 2010
                • 83

                #8
                Hi Neopa

                Got it working to what I want it to do.

                Code:
                Private Sub chkAddToTaxZone_AfterUpdate()
                        Me.NoOfDays = (-1) * NoOfDays
                        Me.FNTotal = (-1) * FNTotal
                End Sub
                It is toggling the values from positive to negative and vice versa.
                Last edited by NeoPa; May 14 '15, 01:08 AM. Reason: Stripped extra white space.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  Excellent. I was convinced Joe's suggestion would work for you.

                  As a matter of interest you can also express it as :
                  Code:
                  Private Sub chkAddToTaxZone_AfterUpdate()
                      With Me
                          .NoOfDays = -.NoOfDays
                          .FNTotal = -.FNTotal
                      End With
                  End Sub
                  That won't make it work better as it already works fine. It is simply a tidier way of expressing it in VBA.

                  Comment

                  • hrprabhu
                    New Member
                    • May 2010
                    • 83

                    #10
                    Thanks NeoPa...Access is like an ocean. I thought I knew a lot, now I feel I have just dipped my toes.

                    Thanks for your help...

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      Originally posted by hrprabhu
                      hrprabhu:
                      Thanks NeoPa...Access is like an ocean. I thought I knew a lot, now I feel I have just dipped my toes.
                      That's so very true. I get the same feeling sometimes ;-)

                      However, it's not about what you don't know. It's about what you know. As long as you keep inreasing the latter then the size of the former will be less and less important.

                      Comment

                      Working...