loop and recordset
- From: Lan <Lan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 2 Jan 2007 13:57:01 -0800
Hi
below is my recordset. They are enrollment records. I want to identify
those members whose membership lapsed. In this case, ID 222, his membership
elaped three months from May to July. ID 333's membership elapsed 1 month.
I am trying to write the code that will generate me that information
(member ID)
Original_Recip_Id First_Dt_Of_Service Last_Dt_Of_Service
111 11/9/2006 11/30/2006
111 12/1/2006 12/31/2006
222 4/1/2006 4/30/2006
222 8/1/2006 8/26/2006
333 4/1/2006 4/30/2006
333 6/1/2006 6/10/2006
Here is what I have so far. It gives me the right information. But it
cannot detect the end of recordset. Error message: "either EOR or EOF is
True, or the current record has been deleted. Request operation requires a
current record."
Sub myfunction()
'fields in the enrollment tbl: ID, Original_Recip_Id, First_Dt_Of_Service,
Last_Dt_Of_Service
Dim myConnection As ADODB.Connection
Set myConnection = CurrentProject.Connection
Dim rst As New ADODB.Recordset
rst.ActiveConnection = myConnection
rst.Open "enrollment_2", , adOpenStatic
Dim A_ID As String
Dim B_ID As String
Dim A_B_elapse As Double
Dim A_EndDt As Date
Dim B_StartDt As Date
rst.MoveFirst
A_ID = rst.Fields("Original_Recip_Id")
A_EndDt = rst.Fields("Last_Dt_Of_Service")
While Not rst.EOF
rst.MoveNext
B_ID = rst.Fields("Original_Recip_Id")
B_StartDt = rst.Fields("first_dt_of_service")
If Not A_ID = B_ID Then
Do Until A_ID = B_ID
A_ID = B_ID
A_EndDt = rst.Fields("Last_Dt_Of_Service")
rst.MoveNext
B_ID = rst.Fields("Original_Recip_Id")
B_StartDt = rst.Fields("first_Dt_of_service")
A_B_elapse = B_StartDt - A_EndDt
Loop
End If
A_B_elapse = B_StartDt - A_EndDt
If A_B_elapse <> 1 Then
Debug.Print A_ID, B_ID, A_EndDt, B_StartDt, A_B_elapse
End If
A_ID = B_ID
A_EndDt = rst.Fields("Last_Dt_Of_Service")
Wend
rst.Close
Set rst = Nothing
Set myConnection = Nothing
End Sub
Please help.
Thank you!!
.
- Follow-Ups:
- Re: loop and recordset
- From: onedaywhen
- RE: loop and recordset
- From: SteveS
- RE: loop and recordset
- From: Gerwin Berentschot
- Re: loop and recordset
- Prev by Date: Re: "Access 2002 Desktop Developer's Handbook" chapter 7 file - does not work w/A2003
- Next by Date: Re: Moving through records and counting
- Previous by thread: RE: outlook automation object error
- Next by thread: RE: loop and recordset
- Index(es):
Relevant Pages
|