"CurrentRecord" doesn't seem reliable

L

Laurel

The code ibelow s executed in a command button. Frequently (more often than
not?) the function that references the recordset passed in the parameter
encounters a "No current record" in its first statement. But not always!
So the code can work. I can't figure out why it would sometimes recognize
the current record and not other times. I'm always sure that the cursor is
on a row in the forms recordset before clicking the command button.

I'd be most grateful if someone could help. I've worked on this all day,
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 tomorrow...
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 Then (NOTE - THIS CODE DOES NOT TRAP THE
PROBLEM.
HOW CAN THE FORM HAVE A CurrentRecord
HERE, BUT NOT IN THE
SUB THAT IS CALLED???)
MsgBox ("No current record" & vbCrLf & "Copy will not be done.")
Exit Sub
End If
Select Case optCopyControls
Case 1
Call subCopyScores1(lrstMe, irst_ClassPeriods)... 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.
.....
 
V

Van T. Dinh

Assuming that you use DAO Recordset, try:

If lrstMe.RecordCount = 0 then
...

HTH
Van T. Dinh
MVP (Access)
 
L

Laurel

If (Me.CurrentRecord = 0) Or (lrstMe.RecordCount = 0) Then
MsgBox ("No current record" & vbCrLf & "Copy will not be done.")
Exit Sub

I'm afraid that I'd been doing that all along, but must have just wiped out
that bit when I put in my comments. Anyway, the puzzle is not that I can't
trap an empty recordset. When I encounter the problem I always have visible
records in the form.
The problem is not the value of CurrentRecord in the test before calling the
sub. It's the fact that Access doesn't think there is a current record once
control goes to the subroutine. But.... not all the time.... I can't figure
out a pattern.
 
V

Van T. Dinh

I meant you don't need (Me.CurrentRecord = 0). This should be enough:

If (lrstMe.RecordCount = 0) Then
MsgBox ("No current record" & vbCrLf & "Copy will not be done.")
Exit Sub

However, it is obviously not the cause of the problem. Assuming that you
use DAO Recordset:

* Try to full declaration justo be sure like:

Dim lrstMe As DAO.Recordset

* Try using ByRef argument in your Sub declaration, i.e.:

Public Sub subCopyScores1(_
ByRef arst_Scores As DAO.RecordSet, _
ByRef arst_periods As DAO.RecordSet)
 
D

david epsom dot com dot au

If you haven't saved the record, there is no record -- just text
on your form. Save the record before you try to do anything.

(david)
 

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