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

How to subtract in Access

WHB
I am creating a DB for following stocks. The table looks like this:
Date, Hi, Lo, Close, Change, Support, Resistance,
I have it all working, except I want access to calculate the Change column
for me. The change is the difference between the close. So if it closed at
50 yesterday and closed at 55 today - the change would be +5. Conversely,
if it closed and 55 yesterday and closed at 50 today then the change would be
-5. IS there an easy way to do this?/
Nov 12 '05 #1
2 9223
On 1 Apr 2004 14:06:20 -0800, wh********@yahoo.com (WHB) wrote:
I am creating a DB for following stocks. The table looks like this:
Date, Hi, Lo, Close, Change, Support, Resistance,
I have it all working, except I want access to calculate the Change column
for me. The change is the difference between the close. So if it closed at
50 yesterday and closed at 55 today - the change would be +5. Conversely,
if it closed and 55 yesterday and closed at 50 today then the change would be
-5. IS there an easy way to do this?/

2 things:
It isn't a good idea to store calculated values. You can always
calculate the difference when you need.
And, Date is a reserved word in Access - not a good idea to use it for
a field name or anything else. It could easily lead to problems when
you later need to code with it.

OK,
for a form or report you could calculate the the Change like ...

Change = Me.Close - DMax("Close", "tblStocks", _
StockDate<#" & Me.StockDate & "#")

Note that I use StockDate for your Date and tblStocks for the name of
the table.
- Jim
Nov 12 '05 #2
On Thu, 01 Apr 2004 22:27:39 GMT, "Jim Allensworth"
<ji****@Notdatacentricsolutions.com> wrote:
On 1 Apr 2004 14:06:20 -0800, wh********@yahoo.com (WHB) wrote:
I am creating a DB for following stocks. The table looks like this:
Date, Hi, Lo, Close, Change, Support, Resistance,
I have it all working, except I want access to calculate the Change column
for me. The change is the difference between the close. So if it closed at
50 yesterday and closed at 55 today - the change would be +5. Conversely,
if it closed and 55 yesterday and closed at 50 today then the change would be
-5. IS there an easy way to do this?/

2 things:
It isn't a good idea to store calculated values. You can always
calculate the difference when you need.
And, Date is a reserved word in Access - not a good idea to use it for
a field name or anything else. It could easily lead to problems when
you later need to code with it.

OK,
for a form or report you could calculate the the Change like ...

Change = Me.Close - DMax("Close", "tblStocks", _
StockDate<#" & Me.StockDate & "#")

Note that I use StockDate for your Date and tblStocks for the name of
the table.

Looking at this again, I believe you would also need an ID for the
stock. And the DMax I suggested won't work. More like...

------------------------------------
Dim strLast As String
Dim rstLast As DAO.Recordset
Dim db As Database

strLast = "SELECT TOP 1 Close FROM tblStocks " _
& "WHERE StockDate<#" & Me.StockDateDate & "# " _
& "AND StockID=" & Me.StockID _
& " ORDER BY StockDate DESC;"

Set db = CurrentDb
Set rstLast = db.OpenRecordset (strLast)
With rstLast
Change = Me.Close - Nz(.Fields(0),0)
.Close
End With
Set rstLast = Nothing
Set db = Nothing
-----------------------------------
- Jim
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Russ Green | last post by:
I'm trying to perform several manipulations to time values (all will be stored in a access database). I need to find the elapsed time between a start time and a finish time and I also need to be...
8
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month"...
3
by: Mo | last post by:
Is it possible to subtract a number of weeks from a specific date field in one of my queries? e.g: CalculatedDateField: MyDatefield - 10 wks Any help much appreciated.
4
by: Lee | last post by:
Hi All, I have a datetime field and want to subtract 24 (or any other number of) hours from it. How would I go about this? Thanks Lee
3
by: S. van Beek | last post by:
Dear reader, With DatePart() you can subtract the year or the week from a date field with: DatePart("yyyy";) for the year
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
2
by: Fabian | last post by:
Friends, I´m making a basic system for sale spare parts cars and have a problem to subtract my new stock against sale on the day. Is possible use a basic consult and foms or necessary I need...
8
by: Remington | last post by:
I am using windows 2000pro with access 2000. I am trying to make a database for our HR department, that would allow our HR Director to type in an employee's ID number into a form and then select...
15
klarae99
by: klarae99 | last post by:
I am working on an Inventory Database in Access 2003. I am working on a report that I could print when its time to file our State Sales Tax paperwork. The figures I need for this report are Total...
1
by: andy143vivi | last post by:
hi, i have a query from 5 tables, and i want to make one of the field to subtract the value from another field, sample: field1: field2: 5 2 4 ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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...
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.