Changing checkbox value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • loisk
    New Member
    • Sep 2007
    • 97

    Changing checkbox value

    Hi,

    If a checkbox is clicked, the value becomes -1.
    Is it possible to change the value -1 to 1?
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Sure!

    Abs(Me.Checkbox Name)

    If you're doing something like adding up checked boxes in a survey, or some such, you can either use the above on each checkbox, or simply use use Abs() on the resultant sum.

    Linq ;0)>

    Comment

    • loisk
      New Member
      • Sep 2007
      • 97

      #3
      Originally posted by missinglinq
      Sure!

      Abs(Me.Checkbox Name)

      If you're doing something like adding up checked boxes in a survey, or some such, you can either use the above on each checkbox, or simply use use Abs() on the resultant sum.

      Linq ;0)>
      Hi,

      Is this the right way to use it?

      Code:
      Private Sub Intvtrac_Click()
      
         If Me.Intvtrac <> "" Then
             Intvtrac = Abs(-1)
         End If
         
      End Sub
      Thanks, Missinglinq!
      Last edited by loisk; Apr 25 '08, 06:52 PM. Reason: spell correction

      Comment

      • loisk
        New Member
        • Sep 2007
        • 97

        #4
        Originally posted by loisk
        Hi,

        Is this the right way to use it?

        Code:
        Private Sub Intvtrac_Click()
        
           If Me.Intvtrac <> "" Then
               Intvtrac = Abs(-1)
           End If
           
        End Sub
        Thanks, Missinglinq!
        I noticed that one problem after the above event.
        Once I clicked and the value became 1 unclicking could not be done. Can you help me on how to make it toggled?

        Comment

        • Stewart Ross
          Recognized Expert Moderator Specialist
          • Feb 2008
          • 2545

          #5
          Hi loisk. You've not quite grasped this one yet; if you look more carefully at Linq's reply to you it was about using Abs(yourcontrol ) in a subsequent query etc. What you have done instead is to change the value of your checkbox intvtrac to 1 - which then prevents it functioning as a checkbox. The value -1 represents boolean True, the checkbox ticked state. Whilst 0 is supposed to represent boolean False, the checkbox unticked state, Access will still accept other values as valid, such as the 1 you have set (making somewhat of a mockery of the concept of a true/false field). But then the checkbox doesn't work any more...

          You must not change intvtrac itself to 1; just leave it as its normal self. In subsequent queries, instead of referring directly to intvtrac just use a calculated field instead, eg:

          IsChecked: Abs(Intvtrac)
          -Stewart

          Originally posted by loisk
          I noticed that one problem after the above event.
          Once I clicked and the value became 1 unclicking could not be done. Can you help me on how to make it toggled?

          Comment

          • loisk
            New Member
            • Sep 2007
            • 97

            #6
            Originally posted by Stewart Ross Inverness
            Hi loisk. You've not quite grasped this one yet; if you look more carefully at Linq's reply to you it was about using Abs(yourcontrol ) in a subsequent query etc. What you have done instead is to change the value of your checkbox intvtrac to 1 - which then prevents it functioning as a checkbox. The value -1 represents boolean True, the checkbox ticked state. Whilst 0 is supposed to represent boolean False, the checkbox unticked state, Access will still accept other values as valid, such as the 1 you have set (making somewhat of a mockery of the concept of a true/false field). But then the checkbox doesn't work any more...

            You must not change intvtrac itself to 1; just leave it as its normal self. In subsequent queries, instead of referring directly to intvtrac just use a calculated field instead, eg:

            IsChecked: Abs(Intvtrac)
            -Stewart
            Hi Stewart! Thanks for your prompt reply!
            The problem I face is that this intvtrac field is bound to the linked table, MySQL, and my boss wants it to be 1 at clicked, but not -1 due to her need to run report later and the scripts of the report doesn't take any negative number, i.e., -1. I don't know how I should handle this problem.

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              1. Change the field in the table from Yes/No to a Numeric Datatype (Integer)
              2. Set it's Default Value as 0
              3. Place a checkbox on your form
              4. Set its ControlSource to the field
              5. Use this code
              field (Integer).
              Code:
              Private Sub Intvtrac_AfterUpdate()
              If Me.Intvtrac Then
                Me.Intvtrac = 1
              Else
                Me.Intvtrac = 0
              End If
              End Sub
              If the box is checked, the field will be set to 1, if it's then later unchecked, it'll be set back to 0. If you already have data in the table, you'll need to change the -1s, either manually or with an update query.

              Linq ;0)>

              Comment

              • loisk
                New Member
                • Sep 2007
                • 97

                #8
                Originally posted by missinglinq
                1. Change the field in the table from Yes/No to a Numeric Datatype (Integer)
                2. Set it's Default Value as 0
                3. Place a checkbox on your form
                4. Set its ControlSource to the field
                5. Use this code
                field (Integer).
                Code:
                Private Sub Intvtrac_AfterUpdate()
                If Me.Intvtrac Then
                  Me.Intvtrac = 1
                Else
                  Me.Intvtrac = 0
                End If
                End Sub
                If the box is checked, the field will be set to 1, if it's then later unchecked, it'll be set back to 0. If you already have data in the table, you'll need to change the -1s, either manually or with an update query.

                Linq ;0)>
                (My datatype for 'Intvtrac' was already integer.)
                It worked!
                Thank you so much, MissingLinq!
                Also thank you to Stewart!

                Comment

                • missinglinq
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3533

                  #9
                  Glad we could help!

                  Linq ;0)>

                  Comment

                  Working...