434,677 Members | 1,070 Online
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

Changing checkbox value

 P: 97 Hi, If a checkbox is clicked, the value becomes -1. Is it possible to change the value -1 to 1? Apr 25 '08 #1
8 Replies

 Expert 2.5K+ P: 3,532 Sure! Abs(Me.CheckboxName) 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)> Apr 25 '08 #2

 P: 97 Sure! Abs(Me.CheckboxName) 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? Expand|Select|Wrap|Line Numbers Private Sub Intvtrac_Click()      If Me.Intvtrac <> "" Then        Intvtrac = Abs(-1)    End If   End Sub Thanks, Missinglinq! Apr 25 '08 #3

 P: 97 Hi, Is this the right way to use it? Expand|Select|Wrap|Line Numbers 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? Apr 25 '08 #4

 Expert Mod 2.5K+ P: 2,545 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 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? Apr 25 '08 #5

 P: 97 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. Apr 25 '08 #6

 Expert 2.5K+ P: 3,532 Change the field in the table from Yes/No to a Numeric Datatype (Integer) Set it's Default Value as 0 Place a checkbox on your form Set its ControlSource to the field Use this code field (Integer). Expand|Select|Wrap|Line Numbers 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)> Apr 25 '08 #7

 P: 97 Change the field in the table from Yes/No to a Numeric Datatype (Integer) Set it's Default Value as 0 Place a checkbox on your form Set its ControlSource to the field Use this code field (Integer). Expand|Select|Wrap|Line Numbers 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! Apr 26 '08 #8

 Expert 2.5K+ P: 3,532 Glad we could help! Linq ;0)> Apr 26 '08 #9