Originally Posted by
alpinegroove
Thank you very much. I tested both suggestions and they both worked.
I'll go with removing rs.MoveFirst. If I don't need it, there is no reason for it to be there...
There are many ways to write code. With all due respect to Paul, I read some where (some when) that there was no guarantee that when a record set was opened that the current record would be the top of the recordset. So I *always* use
rs.MoveFirst
or
rs.MoveLast
rs.MoveFirst
if I want to fully populate the record set before beginning processing.
This is how I would write (modify) your code:
Code:
Private Sub DeleteRole_Click()
On Error GoTo Err_DeleteRole_Click
'Select record
'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 'depreciated
DoCmd.RunCommand acCmdSelectRecord
'Delete record
'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 'depreciated
DoCmd.RunCommand acCmdDeleteRecord
Dim rs As DAO.Recordset
Me.Requery
Set rs = Me.RecordsetClone
rs.MoveFirst
'Do While rs.EOF = False
Do While Not rs.EOF
'if rs![fkRoleID] can have NULLs, you could use the following line (not both)
' If (rs![fkRoleID] = 3) And Not IsNull(rs![fkRoleID]) Then
If rs![fkRoleID] = 3 Then
Me.Parent.CourseHasTA2 = "Yes"
Else
Me.Parent.CourseHasTA2 = "No"
End If
rs.MoveNext
Loop
Exit_DeleteRole_Click:
rs.Close
Set rs = Nothing
Exit Sub
Err_DeleteRole_Click:
If Err.Number <> 3021 Then
MsgBox Err.Description
End If
Resume Exit_DeleteRole_Click
End Sub
Just putting in my 2 cents worth....
(BTW ..not tested )