> Dim DB As DAO.Database
> Dim Rst As DAO.Recordset
[quoted text clipped - 20 lines]
> Loop
> Loop
It works for me too. Good work!
> Corrected Code --- Has been tested
>
[quoted text clipped - 27 lines]
> Applications
> resource@pcdatasheet.com
I think this query solution works too:
Sub CreateServices()
With CurrentProject.Connection
.Execute _
"CREATE TABLE Services" & _
" (client_id VARCHAR(10) NOT NULL" & _
", service_date DATETIME NOT NULL" & _
", admission_date DATETIME NULL" & _
", PRIMARY KEY (client_id,service_date));"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00044', #12/22/2006#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00044', #12/24/2006#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00044', #01/09/2007#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00044', #01/10/2007#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00044', #04/18/2007#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00122', #10/03/2006#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00122', #10/04/2006#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00989', #03/07/2007#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00989', #03/08/2007#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00989', #03/09/2007#);"
.Execute "INSERT INTO Services (client_id, service_date)" & _
" VALUES ('00989', #04/01/2007#);"
End With
End Sub
Query: Preceded by Gap
------------------------
SELECT Services.client_id,
Services.service_date
FROM Services
WHERE (((EXISTS (SELECT s.service_date
FROM Services AS s
WHERE Services.client_id = s.client_id
AND s.service_date = DATEADD('d',-
1,services.service_date))) = False));
Query: Get Admission Dates
---------------------------
SELECT Services.client_id,
Services.service_date,
MAX([Preceded by Gap].[service_date]) AS Admission
FROM Services
INNER JOIN [Preceded by Gap]
ON ([Preceded by Gap].[service_date] <= services.service_date)
AND (Services.client_id = [Preceded by Gap].client_id)
GROUP BY services.client_id,services.service_date;
Query: Update Services Admissions
----------------------------------
UPDATE Services
SET Services.admission_date = dlookup("Admission","Get Admission Dates",
"client_id = '" & Services.client_id & "' AND service_date = #" &
Services.service_date & "#");