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 :
Essentially, because the "3.2" side is a string, it is useless in this formula.
It should be :
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: -
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]
-
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.
13 4737
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.
NeoPa 32,534
Expert Mod 16PB
I'd better register my interest then :)
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: - Table Name=TblDate
-
Project Start Date; Date
-
# of years; Numeric
-
Budget ID; Autonumber; PK
-
- Table Name=TblEntry
-
Entry ID #; Autonumber; PK
-
Name ID #; Numeric; FK
-
Budget ID #; Numeric; FK
-
Salary; Numeric
-
Employee ID #; Numeric; FK
-
Name; String
-
AY Months; Numeric
-
Summer Months; Numeric
-
AY Percent; Numeric
-
Summer Percent; Numeric
-
- Table Name=TblEmployeeCategory
-
Employee ID Number; Autonumber; PK
-
Employee Type; String
-
Change Month; Numeric
-
- Table Name=TblEmployees
-
Name ID #; Autonumber; PK
-
Name; String
-
Employee ID Number; Numeric; FK
-
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.
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: - Table Name=TblDate
-
Project Start Date; Date
-
# of years; Numeric
-
Budget ID; Autonumber; PK
-
- Table Name=TblEntry
-
Entry ID #; Autonumber; PK
-
Name ID #; Numeric; FK
-
Budget ID #; Numeric; FK
-
Salary; Numeric
-
Employee ID #; Numeric; FK
-
Name; String
-
AY Months; Numeric
-
Summer Months; Numeric
-
AY Percent; Numeric
-
Summer Percent; Numeric
-
- Table Name=TblEmployeeCategory
-
Employee ID Number; Autonumber; PK
-
Employee Type; String
-
Change Month; Numeric
-
- Table Name=TblEmployees
-
Name ID #; Autonumber; PK
-
Name; String
-
Employee ID Number; Numeric; FK
-
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.
Always good when you figure things out yourself. Let us know if you run into any more trouble.
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.
I'm not sure I follow, what do you mean by full spread? You mean beyond one year?
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.
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.
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.
Thanks Rabbit,
That seemed to work perfectly.
Not a problem, good luck.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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.
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |