I'm trying to use the following code with a set of nested If statements ... but I'm getting "Loop without Do" error at the fifth line from the bottom: "Loop While Not rsA.EOF"
I think I'm missing an End If? Can anyone help? Thanks-Colleen
------------------------------------
Option Compare Database
Option Explicit
Public Function CalculateServiceLX()
Dim rsA As DAO.Recordset
Dim rsS As DAO.Recordset
Dim lngEmp As Double
Dim dtBeginDate As Date
Dim dtExpireDate As Date
Dim strBeg As String
Dim strType As String
Dim strStatus As String
Dim strAY As String
Dim intCount As Integer
Set rsA = CurrentDb.OpenRecordset("SELECT * FROM [APPOINTMENT] ORDER BY [Employee_Number]")
Set rsS = CurrentDb.OpenRecordset("SELECT * FROM [YEARSOFSERVICE_LX]")
rsA.MoveFirst
lngEmp = rsA!Employee_Number
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
Do
'If we are continuing with the same employee
If lngEmp = rsA!Employee_Number Then
'If we are continuing with the same employee and same service type,
If strType = rsA!FT_PT Then
'If we are continuing with the same employee, same service type, check if semester or year
If Year(dtBeginDate) = Year(dtExpireDate) Then
'semester, keep counting
intCount = intCount + 0.5
If Year(dtBeginDate) <> Year(dtExpireDate) Then
'year, keep counting
intCount = intCount + 1
rsA.MoveNext
'If we are continuing with the same employee but different service type, add to new table
' and reset counters and string variables
Else:
rsA.MovePrevious
rsS.AddNew
rsS!YS_Employee_Number = lngEmp
rsS!YS_Date_Range = strBeg & " - " & rsA!Expire_Date_this_appt
rsS!YS_FT_PT = strType
rsS!YS_Count = intCount
rsS.Update
rsA.MoveNext
If Not rsA.EOF Then
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
End If
End If
'If we have encountered a new employee add to new table and reset counters and string variables
Else:
rsA.MovePrevious
rsS.AddNew
rsS!YS_Employee_Number = lngEmp
rsS!AY_Date_Range = strBeg & " - " & rsA!Expire_Date_this_appt
rsS!YS_FT_PT = strType
rsS!YS_Count = intCount
rsS.Update
rsA.MoveNext
If Not rsA.EOF Then
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
End If
lngEmp = rsA!Employee_Number
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
End If
If rsA.EOF Then
rsA.MovePrevious
rsS.AddNew
rsS!YS_Employee_Number = lngEmp
rsS!YS_Date_Range = strBeg & " - " & rsA!Expire_Date_this_appt
rsS!YS_FT_PT = strType
rsS!YS_Count = intCount
rsS.Update
rsA.MoveNext
End If
Loop While Not rsA.EOF
Set rsA = Nothing
Set rsS = Nothing
MsgBox ("Process Complete!")
End Function
I think I'm missing an End If? Can anyone help? Thanks-Colleen
------------------------------------
Option Compare Database
Option Explicit
Public Function CalculateServiceLX()
Dim rsA As DAO.Recordset
Dim rsS As DAO.Recordset
Dim lngEmp As Double
Dim dtBeginDate As Date
Dim dtExpireDate As Date
Dim strBeg As String
Dim strType As String
Dim strStatus As String
Dim strAY As String
Dim intCount As Integer
Set rsA = CurrentDb.OpenRecordset("SELECT * FROM [APPOINTMENT] ORDER BY [Employee_Number]")
Set rsS = CurrentDb.OpenRecordset("SELECT * FROM [YEARSOFSERVICE_LX]")
rsA.MoveFirst
lngEmp = rsA!Employee_Number
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
Do
'If we are continuing with the same employee
If lngEmp = rsA!Employee_Number Then
'If we are continuing with the same employee and same service type,
If strType = rsA!FT_PT Then
'If we are continuing with the same employee, same service type, check if semester or year
If Year(dtBeginDate) = Year(dtExpireDate) Then
'semester, keep counting
intCount = intCount + 0.5
If Year(dtBeginDate) <> Year(dtExpireDate) Then
'year, keep counting
intCount = intCount + 1
rsA.MoveNext
'If we are continuing with the same employee but different service type, add to new table
' and reset counters and string variables
Else:
rsA.MovePrevious
rsS.AddNew
rsS!YS_Employee_Number = lngEmp
rsS!YS_Date_Range = strBeg & " - " & rsA!Expire_Date_this_appt
rsS!YS_FT_PT = strType
rsS!YS_Count = intCount
rsS.Update
rsA.MoveNext
If Not rsA.EOF Then
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
End If
End If
'If we have encountered a new employee add to new table and reset counters and string variables
Else:
rsA.MovePrevious
rsS.AddNew
rsS!YS_Employee_Number = lngEmp
rsS!AY_Date_Range = strBeg & " - " & rsA!Expire_Date_this_appt
rsS!YS_FT_PT = strType
rsS!YS_Count = intCount
rsS.Update
rsA.MoveNext
If Not rsA.EOF Then
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
End If
lngEmp = rsA!Employee_Number
strBeg = rsA!Begin_Date_this_appt
strType = rsA!FT_PT
dtBeginDate = rsA!Begin_Date_this_appt
dtExpireDate = rsA!Expire_Date_this_appt
intCount = 0
End If
If rsA.EOF Then
rsA.MovePrevious
rsS.AddNew
rsS!YS_Employee_Number = lngEmp
rsS!YS_Date_Range = strBeg & " - " & rsA!Expire_Date_this_appt
rsS!YS_FT_PT = strType
rsS!YS_Count = intCount
rsS.Update
rsA.MoveNext
End If
Loop While Not rsA.EOF
Set rsA = Nothing
Set rsS = Nothing
MsgBox ("Process Complete!")
End Function