CurrentRecord not reliable - repost - urgent

L

Laurel

I'm re-posting this, hopefully more clearly, because I made a mistake in the
original posting, and I know having an answer will slow down more responses,
and I'm desperate to get beyond this before mid-afternoon today. Thanks for
your understanding.

My problem is that in a form with several records showing, when I pass that
form's recordset to a subroutine, the subroutine SOMETIMES (but not
always...so the logic can work) returns the error "No current record" in
its first statement. This is true even though I test both Me.CurrentRecord
and Me.RecordSet.Recordcount before calling it. These values are always
what one would expect. I've been careful to test only with pre-existing
records, to avoid ambiguity with new records being current. I always click
on a row before executing the routine.


I'd be most grateful if someone could help. I worked on this all day
yesterday, and was sure I was about to wrap it up, as the function has been
working nicely until just recently.... Had hoped to show it to the user
today...
sighh...

Note - I'm not yelling with the caps. . I just used them to highlight the
comments inside the script.... Additional explanations/questions.


Dim lrstMe As RecordSet
Set lrstMe = Me.RecordSet
'lrstMe.Update
If (Me.CurrentRecord = 0) Or (lrstMe.RecordCount = 0) Then
THESE VALUES ARE ALWAYS AS EXPECTED
MsgBox ("No current record" & vbCrLf & "Copy will not be done.")
Exit Sub
End If
Select Case optCopyControls
Case 1
Call subCopyScores1(lrstMe, irst_ClassPeriods)
Case 2..... etc

*************
Public Sub subCopyScores1(arst_Scores As RecordSet, arst_periods As
RecordSet)
'Copy the scores from the current row to the rest of the Student's
periods
If (arst_Scores!Period_Code = "B") _ THIS IS WHERE I GET THE
ERROR
Or (arst_Scores!Period_Code = "L") _
Or (arst_Scores!Period_Code = "D") Then
MsgBox ("Periods B, L and D may not be used to generate other
scores.")
Exit Sub
End If
...... etc.
.....
 
D

Douglas J. Steele

Try changing

If (Me.CurrentRecord = 0) Or (lrstMe.RecordCount = 0) Then

to

If lrstMe.BOF And lrstMe.EOF Then
 
L

Laurel

The problem was never that I couldn't get a good value in Me.CurrentRecord
or Me.REcordCount, or any other method of testing. The problem was that
when there were clearly records in the recordset, and these various methods
showed it, I still got a "No Current record."

I narrowed it down to when the focus was on the first row in the recordset.
For a long time the problem only happened the SECOND time I tried to
reference the recordset after it had been retrieved. I Compressed/Repaird
the database, and it began happening the first time..... Go figure. Here is
what I finally did to solve it.


'KLUGE BECAUSE at this point if a value in the form is referenced when
' the focus is on the first record without having explicitly moved there
' from somewhere else (i.e., right after a retrieve)
' you get "No current record" even though Me.CurrentReocrd and
Me.REcordSetCount
' show that there is a current record in a good recordset.

Dim li_CurrentRecord As Integer

li_CurrentRecord = Me.CurrentRecord
If Me.CurrentRecord = 1 Then
gb_SuppressCopyControls = True
lrstMe.MoveLast
lrstMe.MoveFirst
End If
'END OF KLUGE
 

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