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

Urgent VBA Help!


Hey, hope one of you can help wiht this!

I have a table that contains several different clients, each with
their own client_id. Each client has a start and end date as to when
their course starts with us and when it ends. Some clients have
multiple records with different dates where they have done different
courses. Example:

Client_Id Start_Date End Date
1234 01/09/2006 31/10/2006
1234 12/12/2006 01/02/2007
1234 09/02/2007 30/04/2007
1345 01/01/2007 01/03/2007
1289 01/09/2006 31/11/2006
1289 01/09/2006 31/10/2006

For those clients with multiple records I need to count the number of
day bewteen courses. So for client_id 1234 above, I need to know how
many days are between End_date of the first record and the start_date
of the second reocrd. Then I need to know how many days are betweent
he end_date of the second record and start_date of the third record
and so on and on...

This code needs to then repeat for all clients with multiple records -
BUT there is no limit on how many records a client may have.

I think I may need some kind of loop that assigns an auto number to
records but that resets itself on a change of client_id but i have no
idea how to do this! Help!

Laura

May 29 '07 #1
5 1428
This doesn't outline the courses that these people are taking. Based
upon your description of your problem client_id = 1289 doesn't fit the
bill.

Start course on January 9, 2006
End course on November 31 (30?), 2006
Start course January 9, 2006 (time between courses is negative)
End course on October 31, 2006

Cheers,
Jason Lepack

On May 29, 6:06 am, laurajayne.coz...@peterborough.gov.uk wrote:
Hey, hope one of you can help wiht this!

I have a table that contains several different clients, each with
their own client_id. Each client has a start and end date as to when
their course starts with us and when it ends. Some clients have
multiple records with different dates where they have done different
courses. Example:

Client_Id Start_Date End Date
1234 01/09/2006 31/10/2006
1234 12/12/2006 01/02/2007
1234 09/02/2007 30/04/2007
1345 01/01/2007 01/03/2007
1289 01/09/2006 31/11/2006
1289 01/09/2006 31/10/2006

For those clients with multiple records I need to count the number of
day bewteen courses. So for client_id 1234 above, I need to know how
many days are between End_date of the first record and the start_date
of the second reocrd. Then I need to know how many days are betweent
he end_date of the second record and start_date of the third record
and so on and on...

This code needs to then repeat for all clients with multiple records -
BUT there is no limit on how many records a client may have.

I think I may need some kind of loop that assigns an auto number to
records but that resets itself on a change of client_id but i have no
idea how to do this! Help!

Laura

May 29 '07 #2
A possible solution given that course dates do not overlap...

SELECT A.CLIENT_ID,
A.START_DATE,
A.END_DATE,
NZ((SELECT MIN(START_DATE)
FROM LAURAJAYNE AS B
WHERE B.START_DATE A.END_DATE
AND A.CLIENT_ID = B.CLIENT_ID),DATE()) AS
NEXT_START,
DATEDIFF("d",[END_DATE],[NEXT_START]) AS DAYS_BETWEEN
FROM LAURAJAYNE AS A;
On May 29, 6:06 am, laurajayne.coz...@peterborough.gov.uk wrote:
Hey, hope one of you can help wiht this!

I have a table that contains several different clients, each with
their own client_id. Each client has a start and end date as to when
their course starts with us and when it ends. Some clients have
multiple records with different dates where they have done different
courses. Example:

Client_Id Start_Date End Date
1234 01/09/2006 31/10/2006
1234 12/12/2006 01/02/2007
1234 09/02/2007 30/04/2007
1345 01/01/2007 01/03/2007
1289 01/09/2006 31/11/2006
1289 01/09/2006 31/10/2006

For those clients with multiple records I need to count the number of
day bewteen courses. So for client_id 1234 above, I need to know how
many days are between End_date of the first record and the start_date
of the second reocrd. Then I need to know how many days are betweent
he end_date of the second record and start_date of the third record
and so on and on...

This code needs to then repeat for all clients with multiple records -
BUT there is no limit on how many records a client may have.

I think I may need some kind of loop that assigns an auto number to
records but that resets itself on a change of client_id but i have no
idea how to do this! Help!

Laura

May 29 '07 #3


Hi Jason

Ignore 1289 - these are just examples and i havent checked the dates.
None of the dates will ever overlap.

Could you explain the code above? Especially the A. parts - i havent
seen this before when using VBA...

Thanks for your help!

Laura

May 29 '07 #4
Hi Jason

Forget it - I copied your code into an access query rather than a VBa
module and it works 100% spot on! Thanks so much for saving me and my
collegaues so much time!

Laura

May 29 '07 #5
On May 29, 9:02 am, Laura <laurajayne.coz...@peterborough.gov.uk>
wrote:
Hi Jason

Forget it - I copied your code into an access query rather than a VBa
module and it works 100% spot on! Thanks so much for saving me and my
collegaues so much time!

Laura
You got it. It's SQL - the code that's used in queries.

SELECT A.CLIENT_ID,
A.START_DATE,
A.END_DATE,

DATEDIFF("d",[END_DATE],[NEXT_START]) AS DAYS_BETWEEN
FROM LAURAJAYNE AS A;

It selects the client_id, start_date, and end_date from a table called
"LAURAJAYNE". That table is given an alias of "A" (because it's
easier to type and read).

This section is a little more complicated:
NZ((SELECT MIN(START_DATE)
FROM LAURAJAYNE AS B
WHERE B.START_DATE A.END_DATE
AND A.CLIENT_ID = B.CLIENT_ID),DATE()) AS
NEXT_START,

NZ is a function that selects the first of a list of values that is
not null. The query selects the first start date from LAURAJAYNE
(aliased as B) that has a matching clientid and is greater than the
current end_date. Because there may be no record that has a greater
start date, the nz function will then pick DATE(), which returns
todays date.

Cheers,
Jason Lepack

May 29 '07 #6

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

Similar topics

9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
2
by: Dimitri | last post by:
PLEASE HELP,I HAVE A DATABSE WITH MULTIPLE RECORDS AS OUTLINED BELOW EMP NO LEVEL NEXTINCREASE WAGETYPE UNIT 1000 1 0 1000 1000 1 0 1002 ...
8
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error for some of my web application users but not others??? Even though the application runs from a central webserver??? Thanks for...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn"...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
17
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
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...
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
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
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: 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...
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...

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.