T
tw
I have a couple of issues.
The first is I need to know the record count of a record set. I looked in
the help and found this
"RecordCount Property
Returns the number of records accessed in a Recordset object"
It does not seem to return the number of records, but rather the current
positon.
I can get around that by using rs.movelast then saving the count then moving
back to the first record.
My next issue is a little more confusing...
Code below, I snipped some of it to condense. Basically I have a do while
not rs.eof, at the end of the loop I have rs.movenext. Inside the loop I am
opening another record set of the same table (different object) and am
editing in the second table if necessary. (Which actually hasn't been
necessary yet, but it needs to check anyway) When it gets to the bottom of
the loop, just prior to .movenext it is still on the first record as it
should be. When it executes the .movenext statement it jumps to the last
record, when it loops the second time around the loop and gets to the
..movenext statement it is still on the last record. .movenext doesn't even
move it to eof at this point and I'm now in an infinite loop on the last
record. (I have compacted/repaired just in case it was a problem there... no
luck)
What's wrong with my code?
Dim rs as dao.recordset
Dim rsW as dao.recordset
<snip>
Set rs = CurrentDb.OpenRecordset("Select * from [WorkSpaceSchedule]")
Dim intRecCount As Integer
Do While Not rs.EOF
If rs![ss conflict] = False Then
lngEmpID = rs![SS-FK Emp ID]
lngClientID = rs![SS-FK Client ID]
strDay = rs![SS Day]
'Check 6:00-6:14 AM block
strSQLw = "Select * from [WorkSpaceSchedule] "
strSQLw = strSQLw & "where [SS-FK Emp ID] = " & lngEmpID
strSQLw = strSQLw & " and [SS-FK Client ID] = " & lngClientID
strSQLw = strSQLw & " and [SS Day] = '" & strDay & "'"
strSQLw = strSQLw & " and [SS 6AM1] = true"
Set rsW = CurrentDb.OpenRecordset(strSQLw)
If Not rsW.EOF Then
rsW.MoveLast
intRecCount = rsW.RecordCount
If intRecCount > 1 Then
'there are conflicts
rsW.MoveFirst
Do While Not rsW.EOF
'mark each record that has a conflict
With rsW
.Edit
![ss conflict] = True
.Update
End With
rsW.MoveNext
Loop
End If
End If
rsW.Close
Set rsW = Nothing
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
<snip>
The first is I need to know the record count of a record set. I looked in
the help and found this
"RecordCount Property
Returns the number of records accessed in a Recordset object"
It does not seem to return the number of records, but rather the current
positon.
I can get around that by using rs.movelast then saving the count then moving
back to the first record.
My next issue is a little more confusing...
Code below, I snipped some of it to condense. Basically I have a do while
not rs.eof, at the end of the loop I have rs.movenext. Inside the loop I am
opening another record set of the same table (different object) and am
editing in the second table if necessary. (Which actually hasn't been
necessary yet, but it needs to check anyway) When it gets to the bottom of
the loop, just prior to .movenext it is still on the first record as it
should be. When it executes the .movenext statement it jumps to the last
record, when it loops the second time around the loop and gets to the
..movenext statement it is still on the last record. .movenext doesn't even
move it to eof at this point and I'm now in an infinite loop on the last
record. (I have compacted/repaired just in case it was a problem there... no
luck)
What's wrong with my code?
Dim rs as dao.recordset
Dim rsW as dao.recordset
<snip>
Set rs = CurrentDb.OpenRecordset("Select * from [WorkSpaceSchedule]")
Dim intRecCount As Integer
Do While Not rs.EOF
If rs![ss conflict] = False Then
lngEmpID = rs![SS-FK Emp ID]
lngClientID = rs![SS-FK Client ID]
strDay = rs![SS Day]
'Check 6:00-6:14 AM block
strSQLw = "Select * from [WorkSpaceSchedule] "
strSQLw = strSQLw & "where [SS-FK Emp ID] = " & lngEmpID
strSQLw = strSQLw & " and [SS-FK Client ID] = " & lngClientID
strSQLw = strSQLw & " and [SS Day] = '" & strDay & "'"
strSQLw = strSQLw & " and [SS 6AM1] = true"
Set rsW = CurrentDb.OpenRecordset(strSQLw)
If Not rsW.EOF Then
rsW.MoveLast
intRecCount = rsW.RecordCount
If intRecCount > 1 Then
'there are conflicts
rsW.MoveFirst
Do While Not rsW.EOF
'mark each record that has a conflict
With rsW
.Edit
![ss conflict] = True
.Update
End With
rsW.MoveNext
Loop
End If
End If
rsW.Close
Set rsW = Nothing
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
<snip>