By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

Check box problem...

P: 83
Hi All,

Expand|Select|Wrap|Line Numbers
  1. Private Sub chkAddToTaxZone_AfterUpdate()
  2.     If chkAddToTaxZone Then
  3.         Me.NoOfDays = NoOfDays
  4.         Me.FNTotal = FNTotal
  5.     Else
  6.         Me.NoOfDays = (-1) * NoOfDays
  7.         Me.FNTotal = (-1) * FNTotal
  8.     End If
  9.     Me.Requery
  10. End Sub
  11.  
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
May 8 '15 #1

✓ answered by jforbes

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:
Expand|Select|Wrap|Line Numbers
  1.     Me.NoOfDays = (-1) * NoOfDays
  2.     Me.FNTotal = (-1) * FNTotal
  3.     Me.Requery

Share this Question
Share on Google+
10 Replies


jforbes
Expert 100+
P: 1,107
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:
Expand|Select|Wrap|Line Numbers
  1.     Me.NoOfDays = (-1) * NoOfDays
  2.     Me.FNTotal = (-1) * FNTotal
  3.     Me.Requery
May 8 '15 #2

P: 83
jforbes,

Thank you very much!
May 8 '15 #3

NeoPa
Expert Mod 15k+
P: 31,769
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?
May 9 '15 #4

P: 83
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.
May 9 '15 #5

NeoPa
Expert Mod 15k+
P: 31,769
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 :-)
May 10 '15 #6

P: 83
Thanks...Neopa Will try
May 11 '15 #7

P: 83
Hi Neopa

Got it working to what I want it to do.

Expand|Select|Wrap|Line Numbers
  1. Private Sub chkAddToTaxZone_AfterUpdate()
  2.         Me.NoOfDays = (-1) * NoOfDays
  3.         Me.FNTotal = (-1) * FNTotal
  4. End Sub
It is toggling the values from positive to negative and vice versa.
May 12 '15 #8

NeoPa
Expert Mod 15k+
P: 31,769
Excellent. I was convinced Joe's suggestion would work for you.

As a matter of interest you can also express it as :
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkAddToTaxZone_AfterUpdate()
  2.     With Me
  3.         .NoOfDays = -.NoOfDays
  4.         .FNTotal = -.FNTotal
  5.     End With
  6. 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.
May 14 '15 #9

P: 83
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...
May 14 '15 #10

NeoPa
Expert Mod 15k+
P: 31,769
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.
May 14 '15 #11

Post your reply

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