473,383 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Check box problem...

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

10 1653
jforbes
1,107 Expert 1GB
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
jforbes,

Thank you very much!
May 8 '15 #3
NeoPa
32,556 Expert Mod 16PB
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
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
32,556 Expert Mod 16PB
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
Thanks...Neopa Will try
May 11 '15 #7
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
32,556 Expert Mod 16PB
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
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
32,556 Expert Mod 16PB
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

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

Similar topics

1
by: Clevo | last post by:
Hello, I add a javascript check to each input field. I use an onBlur event. But I want to add a "batch check" function to a onSubmit event too. In case of onBlur the call my check like this:...
1
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
12
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
0
by: gwilliam | last post by:
Problem with checkboxes in webpages. I am trying to re-set the values of dinamically created checkboxes in a web page, but no matter what I try the "Checked" property is not set correctly. A...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
4
by: jamesnkk | last post by:
I have seen posting on Spell check problem, but seem like not solution. Therefore I post this question again. How can I spell check on one record and on one field such as Notes in my Form. MS...
7
by: psybert | last post by:
Hello everyone, Long time lurker, first time poster. I'm a beginner coder, and I've taught myself everything with the help and expertise of users and websites like this one. I normally figure out...
1
by: siddiq | last post by:
Hi , Do any one have solution to this problem ? I am using a display tag for pagination in my JSP page. I have a checkbox field as one of the columns. I am using displayTagWrapper class to...
2
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.