473,396 Members | 2,050 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,396 software developers and data experts.

Calculated Field Returning Incorrect Results

77
In answer to your first question - Any character in a string takes up a position in the string whether it's a space or punctuation or any other character.
In answer to the Val() question - Val() should surround any string when used within a formula. Val, basically, converts a string to the numeric equivalent. This can be done automatically in some circumstances by VBA itself, but it is better to do it explicitly as then there is no ambiguity.
Consider the formula :
Expand|Select|Wrap|Line Numbers
  1. 5 * "3.2"
Essentially, because the "3.2" side is a string, it is useless in this formula.
It should be :
Expand|Select|Wrap|Line Numbers
  1. 5 * Val("3.2")
This will always produce the correct result (16).
Thanks NeoPa for your help and explanation. I learn a little more each time.

I have a new problem that I don't understand. I used what was provided to design a query, and I tested it out with type 1 employees, and the numbers matched my expectations:

Expand|Select|Wrap|Line Numbers
  1. Salary1: [Salary]/9*Val(Mid([Spread],1,1))*[AY Percent]+[Salary]/9*Val(Mid([Spread],3,1))*[Summer Percent]+[Salary]/9*Val(Mid([Spread],5,1))*1.034*[AY Percent]+[Salary]/9*Val(Mid([Spread],7,1))*1.034*[Summer Percent]+[Salary]/9*Val(Mid([Spread],9,1))*1.034*1.034*[AY Percent]+[Salary]/9*Val(Mid([Spread],11,1))*1.034*1.034*[Summer Percent]
  2.  
I took this same code, and the only thing I changed was dividing the [Salary] field by 12 instead of 9, but for some reason I'm getting the wrong answers. I looked over the calculations, and I figured out that it is only doing AY calculations, so the 1,5,9 section of the spread. I honestly don't understand why this is happening, but I guess that it has something to do with the VBA code, perhaps the way the variables are structured? Can anyone help me with this?

Thanks.
Mar 12 '07 #1
13 4824
Rabbit
12,516 Expert Mod 8TB
If all you changed was 9 to 12, there is no reason for it not to work.
The only thing the code does is to return the spread of the months in fiscal years split up into academic months and summer months. It has no bearing on anything else. Try making multiple fields that only return the values without doing the calculation to see if all the numbers being returned are correct.

If not, post a detailed explanation and example.
Mar 12 '07 #2
Rabbit
12,516 Expert Mod 8TB
Continued from here.
Mar 12 '07 #3
NeoPa
32,556 Expert Mod 16PB
I'd better register my interest then :)
Mar 12 '07 #4
muhes
77
If all you changed was 9 to 12, there is no reason for it not to work.
The only thing the code does is to return the spread of the months in fiscal years split up into academic months and summer months. It has no bearing on anything else. Try making multiple fields that only return the values without doing the calculation to see if all the numbers being returned are correct.

If not, post a detailed explanation and example.
Hello Rabbit,

Thanks for your advice. It took me a little while, but I was able to eventually isolate the problem. It turned out that I was using the wrong spread; it should have been 1,4,7,10 etc... It just happened that my S2 and AY2 were the same number, so it looked right, even though it was pulling from the wrong place.

I am trying to turn my focus back to the forms. We had discussed this previously, but I'm still a little confused about how I need to structure one part of the form.

The relevant tables being used are:

Use this table structure:
Expand|Select|Wrap|Line Numbers
  1. Table Name=TblDate
  2. Project Start Date; Date
  3. # of years; Numeric
  4. Budget ID; Autonumber; PK
  5.  
  6. Table Name=TblEntry
  7. Entry ID #; Autonumber; PK
  8. Name ID #; Numeric; FK 
  9. Budget ID #; Numeric; FK
  10. Salary; Numeric
  11. Employee ID #; Numeric; FK
  12. Name; String
  13. AY Months; Numeric
  14. Summer Months; Numeric
  15. AY Percent; Numeric
  16. Summer Percent; Numeric
  17.  
  18. Table Name=TblEmployeeCategory
  19. Employee ID Number; Autonumber; PK
  20. Employee Type; String
  21. Change Month; Numeric
  22.  
  23. Table Name=TblEmployees
  24. Name ID #; Autonumber; PK
  25. Name; String
  26. Employee ID Number; Numeric; FK
  27.  
My main form has the fields: TblDate [Project Start Date], [# of years]. My subform has the fields: TblEmployees [Name] TblEntry [Salary], [Name], [AY Months], [AY Percent], [Summer Months], [Summer Percent].

The problem. When I select a new record on the main form, the subform still retains the fields of the previous subform.

Other minor problems: I can't select a number less then 100% for the fields [AY Percent] and [Summer Percent]. Their fields have the properties numeric and percentage.

Thanks as always for the help.
Mar 13 '07 #5
muhes
77
Hello Rabbit,

Thanks for your advice. It took me a little while, but I was able to eventually isolate the problem. It turned out that I was using the wrong spread; it should have been 1,4,7,10 etc... It just happened that my S2 and AY2 were the same number, so it looked right, even though it was pulling from the wrong place.

I am trying to turn my focus back to the forms. We had discussed this previously, but I'm still a little confused about how I need to structure one part of the form.

The relevant tables being used are:

Use this table structure:
Expand|Select|Wrap|Line Numbers
  1. Table Name=TblDate
  2. Project Start Date; Date
  3. # of years; Numeric
  4. Budget ID; Autonumber; PK
  5.  
  6. Table Name=TblEntry
  7. Entry ID #; Autonumber; PK
  8. Name ID #; Numeric; FK 
  9. Budget ID #; Numeric; FK
  10. Salary; Numeric
  11. Employee ID #; Numeric; FK
  12. Name; String
  13. AY Months; Numeric
  14. Summer Months; Numeric
  15. AY Percent; Numeric
  16. Summer Percent; Numeric
  17.  
  18. Table Name=TblEmployeeCategory
  19. Employee ID Number; Autonumber; PK
  20. Employee Type; String
  21. Change Month; Numeric
  22.  
  23. Table Name=TblEmployees
  24. Name ID #; Autonumber; PK
  25. Name; String
  26. Employee ID Number; Numeric; FK
  27.  
My main form has the fields: TblDate [Project Start Date], [# of years]. My subform has the fields: TblEmployees [Name] TblEntry [Salary], [Name], [AY Months], [AY Percent], [Summer Months], [Summer Percent].

The problem. When I select a new record on the main form, the subform still retains the fields of the previous subform.

Other minor problems: I can't select a number less then 100% for the fields [AY Percent] and [Summer Percent]. Their fields have the properties numeric and percentage.

Thanks as always for the help.
Hi Rabbit,

I figured out what I was doing wrong. I had attached the subform to the wrong field of the main form; it needed to be with [Budget ID]. I also realized why I wasn't able to display the % fields; I chose the wrong field size. I should have chosen double.

Thanks.
Mar 14 '07 #6
Rabbit
12,516 Expert Mod 8TB
Always good when you figure things out yourself. Let us know if you run into any more trouble.
Mar 14 '07 #7
muhes
77
Always good when you figure things out yourself. Let us know if you run into any more trouble.
Hi Rabbit,

Yeah, I always feel better when I can figure something out on my own as well.

I've been trying to figure this one out as well, but so far I haven't come up with it. Is there an easy modification that I can make to the VBA code so that it will always calculate the full spread regardless of the number of AY and summer months. This would run as a separate module with a different name.

This wouldn't replace the original code, but would rather be used for a specific agency, so that on the report it would pull from the querries built on this code.

Thanks.
Mar 15 '07 #8
Rabbit
12,516 Expert Mod 8TB
I'm not sure I follow, what do you mean by full spread? You mean beyond one year?
Mar 15 '07 #9
muhes
77
I'm not sure I follow, what do you mean by full spread? You mean beyond one year?
Hi Rabbit,



I'm sorry I didn't explain that very well. What I meant by "full spread", was that it would return results as though there were always full months for both AY and Summer. For example, If you had a start date of 3/1/2007, and 9 AY months, and 3 summer months, the spread would be 3,1,6,2,0,0. But if there were say 2 AY months and 2 summer months, the new spread would be 0,0,2,2,0,0 (which would be the numbers needed for 98% of cases; however, there are a very few instances that would require a calculation based on the 3,1,6,2,0,0 spread regardless of the number of actual months. It's annoying, but that's how they do things. So basically, I want to copy the code, open a second module, paste it, and change the name, and hopefully just pull out the one piece or two pieces that evaluate whether there are less than the full months, and subtract down until there are none. Then I could run a query based on this differently named function and (possibly) get a different answer for the spread.

Thanks.
Mar 16 '07 #10
Rabbit
12,516 Expert Mod 8TB
Hi Rabbit,



I'm sorry I didn't explain that very well. What I meant by "full spread", was that it would return results as though there were always full months for both AY and Summer. For example, If you had a start date of 3/1/2007, and 9 AY months, and 3 summer months, the spread would be 3,1,6,2,0,0. But if there were say 2 AY months and 2 summer months, the new spread would be 0,0,2,2,0,0 (which would be the numbers needed for 98% of cases; however, there are a very few instances that would require a calculation based on the 3,1,6,2,0,0 spread regardless of the number of actual months. It's annoying, but that's how they do things. So basically, I want to copy the code, open a second module, paste it, and change the name, and hopefully just pull out the one piece or two pieces that evaluate whether there are less than the full months, and subtract down until there are none. Then I could run a query based on this differently named function and (possibly) get a different answer for the spread.

Thanks.
Well, you could copy the code, change the name of the function, and manually set AY and Summer months to 9 and 3 respectively instead of having the code DLookup the values from the table.
Mar 16 '07 #11
muhes
77
Well, you could copy the code, change the name of the function, and manually set AY and Summer months to 9 and 3 respectively instead of having the code DLookup the values from the table.
Thanks Rabbit,

That seemed to work perfectly.
Mar 16 '07 #12
Rabbit
12,516 Expert Mod 8TB
Thanks Rabbit,

That seemed to work perfectly.
Not a problem, good luck.
Mar 16 '07 #13
Rabbit
12,516 Expert Mod 8TB
Split to: Conditional Form Opening & Report Filtering
Mar 16 '07 #14

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

Similar topics

1
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For...
5
by: Richard Holliingsworth | last post by:
Hello: Thanks for reading this post. I need to create a metrics (form or report - I don't care which) to display calculated fields about the database (A2002 front end to SQL Server 2K) 1) I...
5
by: John Bahran | last post by:
I am trying to use calculated fields in my query but all the results are zero ven when they're not. Please help. Thanks.
3
by: jburris | last post by:
I have been through enough of these threads to think that this should be an easy fix... but, are there circumstances in which the following code syntax does not work? =!!.Form! (this is out of...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
1
by: egrill | last post by:
I need assistance on how I can keep the results of a calculated field as part of a record. Each time I use the form I loose the previous calculation. I can set-up the form calculation but want to...
10
klarae99
by: klarae99 | last post by:
I am working on an Inventory Database in Access 2003. I am having trouble with a report I designed to show current inventory in stock. I have a form (frmInventory) that is unbound. There are four...
2
by: mkbrady | last post by:
I have a query that includes calculated fields that generate numeric results. I have wrapped conversion functions CLng() and CDdl() around the calculated fields to ensure the data types are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.