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

Looping through a field to display running differences

Overview:
Each Preventative Maintenance (PM) check has to have a running log
of the days that it was completed. For each date, I need to know how
many days it took since the last check. I will need that information
to build reports from.

Current Position:
Right now I have the two tables linked together with a one-to-many
link (tblChecks to tblLog) with the common field being CheckID.

My Approach:
I would like to have a query that will have the date field in one
column, and the running difference in the second column.
I.e.

[Date] [DaysElapsed]
Date[1] ---
Date[2] Date[2]-Date[1]
Date[3] Date[3]-Date[2]
. .
. .
Date[i] Date[i]-Date[i-1]

Pseudo-Code -

For Each CheckID in tblLog
For Each Date
DaysElapsed[i] = DaysElapsed[i]-DaysElapsed[i-1]
Next
Next

I invite solutions that implement VBA to solve the problem. Please
keep in mind that though I have some programming background, I have no
VB or VBA experience. If code is involved, please explain where I
need to enter the code and how to invoke it.

I am comfortable with the Access environment, but have no idea how to
use VBA with it.
Nov 13 '05 #1
5 1428
"TheSho" <sh*************@hcm.honda.com> wrote in message
news:bf**************************@posting.google.c om...
Overview:
Each Preventative Maintenance (PM) check has to have a running log
of the days that it was completed. For each date, I need to know how
many days it took since the last check. I will need that information
to build reports from.
I invite solutions that implement VBA to solve the problem.

Use SQL for this not VBA. Post your simplified table structure with some
sample data and the output you need and someone will be able to help you.
Nov 13 '05 #2
Someone suggested that I provide a sample table and the output I wish to
obtain.

Here they are...

For every entry in the tblCheck table, there is a corresponding log
stored under the DateCompleted field in the tblLog table. The linking
field is CheckID

[DateCompleted] [CheckID]
09/02/03 18
10/01/04 18
10/20/04 18
10/29/04 18
10/20/03 19
07/29/04 19
08/29/04 19
09/29/04 19
10/15/04 19

For each date corresponding to a particular check (i.e. for each
CheckID), I need to know how long it has taken since the last check.

I want the query to look like the following:

[DateComp] [DaysElapsed] [CheckID]
09/02/03 - 18
10/01/04 395.00 18
10/20/04 19.00 18
10/29/04 9.00 18
10/20/03 - 19
07/29/04 283.00 19
08/29/04 31.00 19
09/29/04 31.00 19
10/15/04 16.00 19

If you know of an SQL solution to this, then please provide the code. I
am new to database developing, and I don't know how to look through each
record using SQL. A VBA solution will be okay as well.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
Shobhit Shanker wrote:
I want the query to look like the following:

[DateComp] [DaysElapsed] [CheckID]
09/02/03 - 18
10/01/04 395.00 18
10/20/04 19.00 18
10/29/04 9.00 18
10/20/03 - 19
07/29/04 283.00 19
08/29/04 31.00 19
09/29/04 31.00 19
10/15/04 16.00 19

If you know of an SQL solution to this, then please provide the code. I
am new to database developing, and I don't know how to look through each
record using SQL. A VBA solution will be okay as well.


Presumeably you can make the above query but can't figure out the days
elapsed column, correct?

Combine the datediff function and the now() or date() function. In your
query design view, put this into the field cell:

DaysElapsed:datediff("d", now(), DateComp)

Since this is a PM operation, you may want to look up help on datediff
and explore the firstweekday and firstweek which might have some
significance for you (such as seasonal based PMs).
--
Tim
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #4
"Shobhit Shanker" <sh*************@hcm.honda.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
Someone suggested that I provide a sample table and the output I wish to
obtain.


This should work

select t.DateCompleted,
t.DateCompleted -
(
select max(t2.DateCompleted)
from tblCheck as t2
where t2.CheckID = t.CheckID
and t2.DateCompleted < t.DateCompleted
) as DaysElapsed,
t.CheckID
from tblCheck as t
Nov 13 '05 #5
Hey John,

Thanks a LOT for your code. It did EXACTLY what I wanted!

Cheers,

Shobhit

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #6

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

Similar topics

2
by: dave | last post by:
Hi I m facing strange problem... I have one field char type data length 1.. It has data either 1 or 2 in all the field tht I have checked through enterprise manager. I'm running query "select...
2
by: nntp-service.ohio-state.edu | last post by:
Hey folks - I'm a newbie to java script. I'm trying to make a portable data-validator for fields in an HTML form. Ideally, it would work something like this: <input type="text" name="test"...
14
by: Allen Browne | last post by:
Subform is based on a single-table query that contains a calculated field: Amount: Round(CCur(Nz(*,0)),2) Continuous subform displays this field in a text box named Amount. As user enters new...
3
by: Ray | last post by:
I recently upgraded from Access 97 to Access 2003 and just enter some new data into table via an input form. The form has one hyperlink field to contain a file path. In Access 2003, it appears...
5
by: Bruce Lawrence | last post by:
I'm running Access 97 and my modules are looping if someone puts an invalid value in. The setup: 3 macros - get_clock_num, verify_clocknum, append_to_history 3 functions. each in their own...
2
by: Jim in Arizona | last post by:
Usually, If i need special formatting, I don't use the datagrid control and use a loop that processes a table for each record read from the database (as in classic asp) like so: ...
17
by: seajay | last post by:
Hello, I noticed something strange when I was composing a XHTML document with CSS The following DOCTYPE causes the page to display differently on Fireflox 1.0.6 and Internet Explorer 6...
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
1
DebadattaMishra
by: DebadattaMishra | last post by:
Introduction In case of rich applications, you must have observed that a text field behaves like a dynamic combo box. When the user enters some characters in the text field, a popup will come up...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.