No Current Record error

L

Laurel

Can anyone think of what might cause this subroutine to fail at the first
statement after the ELSE with "no current record?" The situation is that 3
rows have been retrieved into the form. The focus arrow is on the first
row. The first time the subroutine is triggered, it works fine, but if it
is triggered again on that same first row, it hits the NO CURRENT RECORD
error. I never get the error if the focus is on row 2 or 3, but I suspect
that is because action has to be taken to make them current i.e., the user
must click on them, because after the subroutine below is executed, focus is
set back to the first record. If the user clicks on one of the other
records and then back on the first record, the subroutine works fine. In
other words, the error seems to occur if the user hasn't explicitly clicked
on the row before it is triggered unless it triggered immediately after the
rows are retrieved.

Private Sub cmdMassUpdate_Click()
Dim lngRecCount As Long
Dim lrstMe As Recordset

If IsNull(txtPeriod) Then
MsgBox ("There is no row in tblPeriods for period " & cboPeriod_Code
_
& vbCrLf & "Mass Update will not be performed.")
Exit Sub
End If
is_Debug = Me!Student_ID
DoCmd.RunCommand acCmdSaveRecord 'Make sure newly added row is
recognized
is_Debug = Me!Student_ID
Set lrstMe = Me.Recordset
If lrstMe.RecordCount = 0 Then
MsgBox ("There are no rows." _
& vbCrLf & "The scores will not be copied.")
Exit Sub
'Empty Recordset
Else
is_Debug = lrstMe!Student_ID THIS IS WHERE THE NO CURRENT RECORD
ERROR OCCURS
lrstMe.MoveLast
is_Debug = lrstMe!Student_ID
lrstMe.MoveFirst
is_Debug = lrstMe!Student_ID
 
K

Ken Snell [MVP]

Somehow, the form's recordset must be being set to before the first record.
I'm guessing that there is other code running in the form as well, and
perhaps that code is causing this to occur. Post the rest of the code that
is in the form's module.
 
L

Laurel

Thanks for the suggestion. There's lots of code that's executed between
times, so I will examine it with your suggestion in mind. In the meantime,
even if I find it, what can I do to force a record to be current before the
user can click the button again?
 
K

Ken Snell [MVP]

You can force the first record to be the current one by using this code
step:

Me.Recordset.MoveFirst

Insert that in your button's code as the last line and see if that helps.
 
L

Laurel

What is a safe test that I don't attempt that if there are no records in the
recordset? It seems like an endless circle, since .RecordCount isn't
reliable without the MOVELAST maneuver, and .MOVEFIRST fails if there are no
records.
 
K

Ken Snell [MVP]

An accurate record count can be obtained once the recordset has gone to the
last record. However, a safe way to test if a recordset is empty is to test
if it's = 0. An empty recordset will have a recordset.recordcount = 0; a
nonempty recordset has a recordcount <> 0 (can be -1 or any positive
number).

Alternatively, an empty recordset will simultaneously have its EOF and BOF
properties = True.
--

Ken Snell
<MS ACCESS MVP>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top