473,327 Members | 1,930 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,327 software developers and data experts.

Calculated field from calculated fields

3
Hi and thanks in advance,
I am using DMin and DMax to calculate date fields in a form.
I need to use these calculated dates in another calculated field.

example:
=DMax("[B&MPayPeriodStartDate]","B&MPayPeriod"," [B&MSalesDate] >= [B&MPayPeriodStartDate] ")
This code calculates the starting date for a pay period and places it in a text box in my form.

example:
=DMin("[B&MPayPeriodEndDate]","B&MPayPeriod"," [B&MSalesDate] <= [B&MPayPeriodEndDate] ")
This code calculates the ending date for a pay period and places it in a text box in my form.

I now need to calculate the sum of sales between the two dates listed above. I've tried everything I can think of. And spent hours searching Access help and google but keep coming up blank. Any help will be greatly appreciated.

Thanks

Dale
Oct 26 '06 #1
2 1948
NeoPa
32,556 Expert Mod 16PB
If you want to use the D-series functions (rather than SQL) in code (and guessing the sales field is something like [B&MPaySales]) then :-

Expand|Select|Wrap|Line Numbers
  1. Dim    datStart As Date, datEnd As Date
  2. Dim    strStart As String, strEnd As String
  3. Dim    curSales As Currency
  4.  
  5. datStart = DMax("[B&MPayPeriodStartDate]", _
  6.                 "[B&MPayPeriod]", _
  7.                 "[B&MSalesDate] >= [B&MPayPeriodStartDate]")
  8. datEnd = DMin("[B&MPayPeriodEndDate]", _
  9.               "[B&MPayPeriod]", _
  10.               "[B&MSalesDate] <= [B&MPayPeriodEndDate]")
  11. strStart = Format(datStart, "\#MM/DD/YYYY\#")
  12. strEnd = Format(datEnd, "\#MM/DD/YYYY\#")
  13. curSales = DSum("[B&MPaySales]", _
  14.                 "[B&MPayPeriod]", _
  15.                 "[B&MSalesDate] Between " & strStart & " And " & strEnd)
Bearing in mind - SQL always expects dates in USA format (MM/DD/YYYY) and the '#' character is the 'surrounder' for Date literals just as the single-quote (') character is for SQL string literals.
Oct 26 '06 #2
EdDale
3
Hi and thanks for the very helpful reply,

While waiting, hoping, for a reply I tried once more to do this with DSum in a calculated field with Expression Builder. I must have had a typo that I could not find the first time I tried because it worked fine this time. I've listed the code I used below.

=DSum("[B&MSalesAmt]","B&MFleaMkt","[B&MSalesDate] >= PayPeriodStart AND [B&MSalesDate] <= PayPeriodEnd")

B&MSalesAmt is the field, in a table, that holds the amount of each sale. PayPeriodStart is the name of the calculated field for my starting date. PayPeriodEnd is the name of the calculated field for the ending date.

I took this one more step and created another calculated field that shows the amount due for any given pay period. There is a 3% deduction from total sales for pay periods that end after 9-1-06. There is a 2% deduction from total sales for pay periods that end before 9-1-06. Here is the Expression Builder code I used for this field.

=IIf([PayPeriodEnd]>=9-1-6,DSum("[B&MSalesAmt]","B&MFleaMkt","[B&MSalesDate] >= PayPeriodStart AND [B&MSalesDate] <= PayPeriodEnd")*0.97,DSum("[B&MSalesAmt]","B&MFleaMkt","[B&MSalesDate] >= PayPeriodStart AND [B&MSalesDate] <= PayPeriodEnd")*0.98)

If there is something wrong with what I have done please do not hesitate to tell me. As you have probably guessed; I don't know much about what I am doing. My normal method of operation is to search Access help until I find something
that looks like it will work. The D series functions were the first I ran across that
appeared to be what I needed. That was the only reason for using them.

Thanks again for the reply,

Dale
Oct 26 '06 #3

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

Similar topics

3
by: Anonymous | last post by:
Hi all, I have a form people use to enter checking data. One of the fields is calculated based on finding the difference of two input fields on the form. Here are the fields: CheckAmount...
1
by: Miguelito Bain | last post by:
hi everybody. i'm trying to find out what you can and can't do with/in calculated fields. any help, pointers, and/or advice would be greatly appreciated. i'm a newbie, but i want to learn, and...
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.
2
by: david | last post by:
Hi, I have a form with a couple of calculated fields. I want to put some code into the 'Form-Load' event to set various object states on the form, depending on the value of these fields. The...
2
by: Olveres | last post by:
Hi, I have managed to work out how to add new lines into a calculated text box. However in this text box some of the outcome fields are empty however when previewing the report it includes the...
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...
9
by: Haas C | last post by:
Hi all! Is there anyway I can override a value in a calculated field on a form? For example: I have a form which displays the following fields based on a query: Premium Due field has the...
3
by: Matthew Wells | last post by:
If I have a calculated field that returns a value from a udf, does that field get calculated even when it's not being used in a Select statement? I knw that if a calculated field's formula is...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.