By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 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
Share this Question
Share on Google+
8 Replies


missinglinq
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
  1. Private Sub Intvtrac_Click()
  2.  
  3.    If Me.Intvtrac <> "" Then
  4.        Intvtrac = Abs(-1)
  5.    End If
  6.  
  7. End Sub
Thanks, Missinglinq!
Apr 25 '08 #3

P: 97
Hi,

Is this the right way to use it?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Intvtrac_Click()
  2.  
  3.    If Me.Intvtrac <> "" Then
  4.        Intvtrac = Abs(-1)
  5.    End If
  6.  
  7. 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

missinglinq
Expert 2.5K+
P: 3,532
  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).
Expand|Select|Wrap|Line Numbers
  1. Private Sub Intvtrac_AfterUpdate()
  2. If Me.Intvtrac Then
  3.   Me.Intvtrac = 1
  4. Else
  5.   Me.Intvtrac = 0
  6. End If
  7. 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
  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).
Expand|Select|Wrap|Line Numbers
  1. Private Sub Intvtrac_AfterUpdate()
  2. If Me.Intvtrac Then
  3.   Me.Intvtrac = 1
  4. Else
  5.   Me.Intvtrac = 0
  6. End If
  7. 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

missinglinq
Expert 2.5K+
P: 3,532
Glad we could help!

Linq ;0)>
Apr 26 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.